/* =========================================================
   E-V Responsive UI
   PC / Tablet / Mobile / iPhone / Android
   ========================================================= */

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --background: #ffffff;
  --sidebar: #f7f7f8;
  --border: #e5e5e5;
  --text: #202123;
  --muted: #6b6b6b;
  --hover: #ececec;
  --user: #f4f4f4;
  --assistant: #f7f7f8;
  --online: #22c55e;
}

/* =========================================================
   기본
   ========================================================= */

html {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

body {
  width: 100%;
  height: 100%;
  min-height: 100%;
  margin: 0;

  font-family:
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    "Noto Sans KR",
    "Apple SD Gothic Neo",
    Arial,
    sans-serif;

  background: var(--background);
  color: var(--text);

  overflow: hidden;

  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

button,
textarea {
  font: inherit;
}

button {
  border: 0;
  background: transparent;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

textarea {
  -webkit-appearance: none;
  appearance: none;
}

/* =========================================================
   앱 전체
   ========================================================= */

.app {
  display: flex;

  width: 100%;
  height: 100vh;
  height: 100dvh;

  min-height: 0;

  overflow: hidden;
}

/* =========================================================
   사이드바
   ========================================================= */

.sidebar {
  display: flex;
  flex-direction: column;

  width: 260px;
  height: 100%;

  background: var(--sidebar);
  border-right: 1px solid var(--border);

  flex-shrink: 0;
}

.sidebar-top {
  padding: 18px 14px;
}

.logo {
  display: flex;
  align-items: center;

  gap: 10px;

  padding: 4px 8px 18px;

  font-size: 20px;
  font-weight: 700;
}

.logo-mark {
  display: flex;
  align-items: center;
  justify-content: center;

  width: 32px;
  height: 32px;

  border-radius: 9px;

  background: #111;
  color: #fff;

  font-size: 16px;
  font-weight: 700;

  flex-shrink: 0;
}

.new-chat-button {
  display: flex;
  align-items: center;

  gap: 10px;

  width: 100%;
  height: 44px;

  padding: 0 14px;

  border: 1px solid var(--border);
  border-radius: 9px;

  background: #fff;
  color: var(--text);

  font-size: 14px;
  font-weight: 500;

  transition:
    background 0.15s ease,
    border-color 0.15s ease;
}

.new-chat-button:hover {
  background: var(--hover);
}

.plus {
  font-size: 21px;
  line-height: 1;
  font-weight: 300;
}

/* =========================================================
   대화 기록
   ========================================================= */

.sidebar-history {
  flex: 1;

  min-height: 0;

  padding: 8px 10px;

  overflow-y: auto;
  overflow-x: hidden;

  -webkit-overflow-scrolling: touch;
}

.history-title {
  padding: 10px 8px;

  color: var(--muted);

  font-size: 12px;
  font-weight: 600;
}

.history-item {
  display: block;

  width: 100%;

  padding: 10px 12px;

  border-radius: 8px;

  color: var(--text);

  text-align: left;

  font-size: 14px;

  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;

  transition: background 0.15s ease;
}

.history-item:hover,
.history-item.active {
  background: var(--hover);
}

/* =========================================================
   사이드바 하단 상태
   ========================================================= */

.sidebar-bottom {
  padding: 14px;

  border-top: 1px solid var(--border);

  flex-shrink: 0;
}

.server-status {
  display: flex;
  align-items: center;

  gap: 10px;

  padding: 8px;
}

.status-dot {
  width: 8px;
  height: 8px;

  border-radius: 50%;

  background: var(--online);

  flex-shrink: 0;
}

.status-dot:not(.online) {
  background: #aaa;
}

.status-info {
  display: flex;
  flex-direction: column;

  gap: 2px;

  min-width: 0;
}

.status-name {
  font-size: 13px;
  font-weight: 600;
}

.status-model {
  color: var(--muted);

  font-size: 11px;

  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* =========================================================
   메인
   ========================================================= */

.main {
  position: relative;

  display: flex;
  flex-direction: column;

  width: calc(100% - 260px);
  height: 100%;

  min-width: 0;
  min-height: 0;

  background: #fff;
}

/* =========================================================
   헤더
   ========================================================= */

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;

  width: 100%;
  min-height: 58px;
  height: 58px;

  padding: 0 22px;

  border-bottom: 1px solid var(--border);

  background: rgba(255, 255, 255, 0.96);

  flex-shrink: 0;

  z-index: 20;
}

.header-left,
.header-right {
  display: flex;
  align-items: center;

  min-width: 0;
}

.model-selector {
  display: flex;
  align-items: center;

  gap: 7px;

  font-size: 16px;
  font-weight: 600;

  white-space: nowrap;
}

.model-arrow {
  color: var(--muted);
  font-size: 18px;
}

.mobile-menu {
  display: none;

  width: 40px;
  height: 40px;

  margin-right: 4px;

  border-radius: 10px;

  font-size: 20px;

  align-items: center;
  justify-content: center;
}

.mobile-menu:hover {
  background: var(--hover);
}

/* =========================================================
   연결 상태
   ========================================================= */

.connection-status {
  display: flex;
  align-items: center;

  gap: 7px;

  color: var(--muted);

  font-size: 12px;

  white-space: nowrap;
}

/* =========================================================
   채팅 영역
   ========================================================= */

.chat-container {
  flex: 1;

  width: 100%;
  min-height: 0;

  overflow-y: auto;
  overflow-x: hidden;

  scroll-behavior: smooth;

  -webkit-overflow-scrolling: touch;
}

/* =========================================================
   Welcome
   ========================================================= */

.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;

  width: 100%;
  min-height: 100%;

  padding:
    40px 20px 180px;

  text-align: center;
}

.welcome-logo {
  display: flex;
  align-items: center;
  justify-content: center;

  width: 58px;
  height: 58px;

  margin-bottom: 22px;

  border-radius: 16px;

  background: #111;
  color: #fff;

  font-size: 28px;
  font-weight: 700;
}

.welcome h1 {
  margin-bottom: 10px;

  font-size: 28px;
  font-weight: 600;

  letter-spacing: -0.6px;
}

.welcome p {
  max-width: 500px;

  color: var(--muted);

  font-size: 14px;

  line-height: 1.6;
}

/* =========================================================
   메시지
   ========================================================= */

.messages {
  display: flex;
  flex-direction: column;

  width: min(900px, 100%);

  margin: 0 auto;

  padding:
    30px 22px 190px;
}

.message {
  display: flex;

  width: 100%;

  margin-bottom: 20px;

  min-width: 0;
}

.message.user {
  justify-content: flex-end;
}

.message.assistant {
  justify-content: flex-start;

  padding-left: 0;
  padding-right: 40px;
}

.message-content {
  line-height: 1.65;

  font-size: 15px;

  white-space: pre-wrap;

  word-break: break-word;
  overflow-wrap: anywhere;

  min-width: 0;
}

/* =========================================================
   사용자 메시지
   ========================================================= */

.message.user .message-content {
  max-width: 75%;

  padding: 12px 15px;

  border-radius: 14px;

  background: var(--user);
  color: var(--text);
}

/* =========================================================
   E-V 메시지
   ========================================================= */

.message.assistant .message-content {
  max-width: 75%;

  padding: 12px 15px;

  border-radius: 14px;

  background: var(--assistant);
  color: var(--text);

  line-height: 1.65;
}

/* =========================================================
   로딩
   ========================================================= */

.message.assistant.loading .message-content::after {
  content: "";

  display: inline-block;

  width: 5px;
  height: 5px;

  margin-left: 6px;

  border-radius: 50%;

  background: #999;

  vertical-align: middle;

  animation: loading-dot 1s infinite ease-in-out;
}

@keyframes loading-dot {

  0%,
  100% {
    opacity: 0.25;
  }

  50% {
    opacity: 1;
  }
}

/* =========================================================
   입력 영역
   ========================================================= */

.input-area {
  position: absolute;

  left: 50%;
  bottom: 0;

  width: min(900px, calc(100% - 44px));

  transform: translateX(-50%);

  padding:
    16px 0 max(20px, env(safe-area-inset-bottom));

  background:
    linear-gradient(to bottom,
      rgba(255, 255, 255, 0),
      rgba(255, 255, 255, 0.96) 20%,
      #fff 45%);

  z-index: 10;
}

/* =========================================================
   입력 박스
   ========================================================= */

.input-wrapper {
  display: flex;
  align-items: flex-end;

  width: 100%;
  min-height: 56px;

  padding:
    8px 8px 8px 14px;

  border: 1px solid #d9d9d9;
  border-radius: 18px;

  background: #fff;

  box-shadow:
    0 2px 10px rgba(0, 0, 0, 0.05);

  transition:
    border-color 0.15s ease,
    box-shadow 0.15s ease;
}

.input-wrapper:focus-within {
  border-color: #bdbdbd;

  box-shadow:
    0 2px 12px rgba(0, 0, 0, 0.08);
}

/* =========================================================
   공통 버튼
   ========================================================= */

.voice-button,
.speech-button,
.send-button {
  display: flex;
  align-items: center;
  justify-content: center;

  width: 40px;
  height: 40px;

  flex-shrink: 0;

  border-radius: 10px;

  -webkit-tap-highlight-color: transparent;
}

/* =========================================================
   음성 입력
   ========================================================= */

.voice-button {
  color: #555;

  transition:
    background 0.15s ease,
    color 0.15s ease;
}

.voice-button:hover {
  background: var(--hover);
  color: #111;
}

.voice-button.active {
  background: #111;
  color: #fff;
}

.voice-button.active:hover {
  background: #333;
  color: #fff;
}

.voice-button svg {
  width: 21px;
  height: 21px;

  fill: none;

  stroke: currentColor;
  stroke-width: 1.8;

  stroke-linecap: round;
  stroke-linejoin: round;
}

/* =========================================================
   E-V 음성 출력
   ========================================================= */

.speech-button {
  margin-left: 2px;

  color: #555;

  transition:
    background 0.15s ease,
    color 0.15s ease,
    transform 0.1s ease;
}

.speech-button:hover {
  background: var(--hover);
  color: #111;
}

.speech-button.active {
  background: #111;
  color: #fff;
}

.speech-button.active:hover {
  background: #333;
  color: #fff;
}

.speech-button:active {
  transform: scale(0.94);
}

.speech-button svg {
  width: 21px;
  height: 21px;

  fill: none;

  stroke: currentColor;
  stroke-width: 1.8;

  stroke-linecap: round;
  stroke-linejoin: round;
}

/* =========================================================
   입력창
   ========================================================= */

#messageInput {
  flex: 1;

  width: 100%;
  min-width: 0;

  min-height: 40px;
  max-height: 180px;

  padding: 9px 10px;

  border: 0;
  outline: 0;

  background: transparent;
  color: var(--text);

  resize: none;

  line-height: 1.5;

  font-size: 16px;

  overflow-y: auto;

  -webkit-appearance: none;
  appearance: none;
}

#messageInput::placeholder {
  color: #999;
}

/* =========================================================
   보내기
   ========================================================= */

.send-button {
  margin-left: 2px;

  background: #111;
  color: #fff;

  transition:
    background 0.15s ease,
    transform 0.1s ease;
}

.send-button:hover {
  background: #333;
}

.send-button:active {
  transform: scale(0.94);
}

.send-button:disabled {
  background: #ccc;
  cursor: not-allowed;
}

.send-button svg {
  width: 19px;
  height: 19px;

  fill: none;

  stroke: currentColor;
  stroke-width: 2;

  stroke-linecap: round;
  stroke-linejoin: round;
}

/* =========================================================
   안내
   ========================================================= */

.input-notice {
  padding-top: 8px;

  color: #999;

  text-align: center;

  font-size: 10px;

  line-height: 1.4;
}

/* =========================================================
   스크롤바
   ========================================================= */

.chat-container::-webkit-scrollbar,
.sidebar-history::-webkit-scrollbar {
  width: 6px;
}

.chat-container::-webkit-scrollbar-thumb,
.sidebar-history::-webkit-scrollbar-thumb {
  border-radius: 10px;

  background: #d5d5d5;
}

.chat-container::-webkit-scrollbar-track,
.sidebar-history::-webkit-scrollbar-track {
  background: transparent;
}

/* =========================================================
   태블릿
   ========================================================= */

@media (max-width: 1024px) {
  .sidebar {
    width: 230px;
  }

  .main {
    width: calc(100% - 230px);
  }

  .messages {
    width: 100%;

    padding-left: 18px;
    padding-right: 18px;
  }

  .input-area {
    width: calc(100% - 36px);
  }

  .message.user .message-content,
  .message.assistant .message-content {
    max-width: 82%;
  }
}

/* =========================================================
   모바일
   ========================================================= */

@media (max-width: 768px) {

  html,
  body {
    width: 100%;
    height: 100%;
  }

  body {
    overflow: hidden;
  }

  .app {
    width: 100%;

    height: 100vh;
    height: 100dvh;

    min-height: 0;
  }

  /* -------------------------------------------------------
     사이드바 숨김
     ------------------------------------------------------- */

  .sidebar {
    display: none;
  }

  /* -------------------------------------------------------
     메인
     ------------------------------------------------------- */

  .main {
    width: 100%;
    height: 100%;

    min-width: 0;
  }

  /* -------------------------------------------------------
     헤더
     ------------------------------------------------------- */

  .header {
    height: 54px;
    min-height: 54px;

    padding:
      0 12px;

    padding-top: env(safe-area-inset-top);

    height: calc(54px + env(safe-area-inset-top));
  }

  .mobile-menu {
    display: flex;
  }

  .model-selector {
    font-size: 15px;
  }

  .connection-status {
    display: none;
  }

  /* -------------------------------------------------------
     Welcome
     ------------------------------------------------------- */

  .welcome {
    min-height: 100%;

    padding:
      30px 18px 160px;
  }

  .welcome-logo {
    width: 52px;
    height: 52px;

    margin-bottom: 18px;

    border-radius: 14px;

    font-size: 25px;
  }

  .welcome h1 {
    margin-bottom: 8px;

    font-size: 24px;

    letter-spacing: -0.5px;
  }

  .welcome p {
    max-width: 320px;

    font-size: 13px;
  }

  /* -------------------------------------------------------
     메시지
     ------------------------------------------------------- */

  .messages {
    width: 100%;

    margin: 0;

    padding:
      20px 12px 170px;
  }

  .message {
    margin-bottom: 14px;
  }

  .message.user .message-content,
  .message.assistant .message-content {
    max-width: 88%;

    padding:
      10px 12px;

    border-radius: 13px;

    font-size: 15px;
    line-height: 1.6;
  }

  .message.assistant {
    padding-right: 8px;
  }

  /* -------------------------------------------------------
     입력 영역
     ------------------------------------------------------- */

  .input-area {
    left: 0;
    bottom: 0;

    width: 100%;

    transform: none;

    padding:
      8px 10px max(10px, env(safe-area-inset-bottom));

    background:
      linear-gradient(to bottom,
        rgba(255, 255, 255, 0),
        rgba(255, 255, 255, 0.98) 18%,
        #fff 38%);
  }

  .input-wrapper {
    min-height: 52px;

    padding:
      6px 6px 6px 9px;

    border-radius: 16px;
  }

  /* -------------------------------------------------------
     버튼
     ------------------------------------------------------- */

  .voice-button,
  .speech-button,
  .send-button {
    width: 38px;
    height: 38px;

    border-radius: 9px;
  }

  .voice-button svg,
  .speech-button svg {
    width: 20px;
    height: 20px;
  }

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

  /* -------------------------------------------------------
     모바일 입력
     ------------------------------------------------------- */

  #messageInput {
    min-height: 38px;

    padding:
      8px 7px;

    font-size: 16px;

    line-height: 1.45;
  }

  /* -------------------------------------------------------
     안내문
     ------------------------------------------------------- */

  .input-notice {
    padding-top: 5px;

    font-size: 9px;
  }

  /* -------------------------------------------------------
     스크롤바 제거
     ------------------------------------------------------- */

  .chat-container::-webkit-scrollbar {
    width: 0;
  }

  .chat-container {
    scrollbar-width: none;
  }
}

/* =========================================================
   작은 스마트폰
   ========================================================= */

@media (max-width: 480px) {
  .header {
    padding-left: 8px;
    padding-right: 8px;
  }

  .mobile-menu {
    width: 38px;
    height: 38px;

    margin-right: 2px;
  }

  .model-selector {
    font-size: 14px;
  }

  .messages {
    padding:
      18px 9px 165px;
  }

  .message.user .message-content,
  .message.assistant .message-content {
    max-width: 92%;

    padding:
      9px 11px;

    font-size: 14px;

    border-radius: 12px;
  }

  .message.assistant {
    padding-right: 4px;
  }

  .input-area {
    padding-left: 7px;
    padding-right: 7px;
  }

  .input-wrapper {
    min-height: 50px;

    padding:
      5px 5px 5px 7px;

    border-radius: 15px;
  }

  .voice-button,
  .speech-button,
  .send-button {
    width: 36px;
    height: 36px;
  }

  #messageInput {
    padding:
      7px 5px;

    font-size: 16px;
  }
}

/* =========================================================
   아주 작은 화면
   ========================================================= */

@media (max-width: 360px) {
  .model-selector {
    font-size: 13px;
  }

  .model-arrow {
    font-size: 15px;
  }

  .messages {
    padding-left: 7px;
    padding-right: 7px;
  }

  .message.user .message-content,
  .message.assistant .message-content {
    max-width: 94%;

    font-size: 14px;
  }

  .voice-button,
  .speech-button,
  .send-button {
    width: 34px;
    height: 34px;
  }

  .voice-button svg,
  .speech-button svg {
    width: 18px;
    height: 18px;
  }

  .send-button svg {
    width: 17px;
    height: 17px;
  }
}

/* =========================================================
   가로 모드 스마트폰
   ========================================================= */

@media (max-width: 768px) and (orientation: landscape) {
  .header {
    height: 48px;
    min-height: 48px;
  }

  .welcome {
    padding:
      20px 15px 120px;
  }

  .welcome-logo {
    width: 42px;
    height: 42px;

    margin-bottom: 10px;

    font-size: 20px;
  }

  .welcome h1 {
    font-size: 20px;
  }

  .messages {
    padding-bottom: 140px;
  }

  .input-area {
    padding-top: 5px;
  }

  .input-notice {
    display: none;
  }
}

/* =========================================================
   터치 디바이스
   ========================================================= */

@media (hover: none) and (pointer: coarse) {
  button {
    touch-action: manipulation;
  }

  .new-chat-button:hover,
  .history-item:hover,
  .voice-button:hover,
  .speech-button:hover,
  .send-button:hover {
    background: initial;
  }

  .new-chat-button:active,
  .history-item:active {
    background: var(--hover);
  }

  .voice-button:active,
  .speech-button:active {
    background: var(--hover);
  }

  .send-button:active {
    background: #333;
  }
}

/* =========================================================
   접근성
   ========================================================= */

@media (prefers-reduced-motion: reduce) {

  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* =========================================================
   다크모드가 시스템에 설정되어 있어도
   현재 E-V 디자인은 화이트 UI를 유지
   ========================================================= */

@media (prefers-color-scheme: dark) {
  /*
   * 의도적으로 비워둡니다.
   *
   * 현재 E-V는 밝은 테마를 기본으로 사용합니다.
   */
}