/* 화면 스타일: 흰 바탕의 깔끔한 채팅 앱 느낌 */

/* 자주 쓰는 색을 변수로 모아 두면, 나중에 한 곳만 바꾸면 된다. */
:root {
  --bg: #ffffff;
  --sidebar-bg: #f9f9f9;
  --border: #e5e5e5;
  --text: #0d0d0d;
  --text-muted: #8f8f8f;
  --accent: #0d0d0d;        /* 주요 버튼(보내기, 추가)은 검은색 */
  --user-bubble: #f4f4f4;
  --hover: #ececec;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", "Malgun Gothic", -apple-system, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
}

button {
  font: inherit;
  cursor: pointer;
}

.layout {
  display: flex;
  height: 100vh;
  height: 100dvh; /* 휴대폰 주소창 높이를 뺀 실제 화면 높이 */
}

/* 아이콘만 있는 둥근 버튼 */
.icon-btn {
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border: none;
  border-radius: 8px;
  background: none;
  color: var(--text-muted);
}
.icon-btn:hover {
  background: var(--hover);
  color: var(--text);
}
svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ── 사이드바 ───────────────────────────────── */
.sidebar {
  width: 260px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--sidebar-bg);
  padding: 8px;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 4px 8px 10px;
}

.logo {
  font-size: 17px;
  font-weight: 600;
}

/* 메뉴: 새 채팅, 검색, 참가자, 설정 */
.side-nav {
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: none;
  border-radius: 8px;
  background: none;
  color: var(--text);
  text-align: left;
  font-size: 14px;
}
.nav-item:hover {
  background: var(--hover);
}
.search-input {
  margin: 2px 4px 4px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  font-size: 14px;
  outline: none;
}

.sidebar-label {
  margin: 18px 10px 4px;
  font-size: 13px;
  color: var(--text-muted);
}

.conversation-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
}

.conversation-item {
  display: flex;
  align-items: center;
  border-radius: 8px;
}
.conversation-item:hover,
.conversation-item.active {
  background: var(--hover);
}
/* 검색에서 걸러진 대화는 숨긴다 (위의 display: flex 가 hidden 을 덮어쓰지 않도록) */
.conversation-item[hidden] {
  display: none;
}

.conversation-title {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  border: none;
  background: none;
  text-align: left;
  color: inherit;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis; /* 긴 제목은 ... 으로 */
}

/* 대화 목록의 ✎(제목 바꾸기), ✕(삭제) 버튼: 마우스를 올리거나 선택된 대화에서만 보인다 */
.item-btn {
  visibility: hidden;
  border: none;
  background: none;
  color: var(--text-muted);
  padding: 4px 6px;
  border-radius: 6px;
}
.conversation-item:hover .item-btn,
.conversation-item.active .item-btn {
  visibility: visible;
}
.item-btn:hover {
  color: var(--text);
  background: #dedede;
}
.delete-btn:hover {
  color: #b33;
  background: #f5dede;
}

/* 아래쪽: 이번 달 사용 금액 */
.profile {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 6px;
  padding: 8px 10px;
  border: none;
  border-top: 1px solid var(--border);
  border-radius: 8px;
  background: none;
  text-align: left;
}
.profile:hover {
  background: var(--hover);
}
.profile-avatar {
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border-radius: 50%;
  background: #d9d9d9;
  font-size: 12px;
}
.profile-text {
  display: flex;
  flex-direction: column;
  font-size: 12px;
  color: var(--text-muted);
}
.profile-text b {
  font-size: 14px;
  color: var(--text);
}

/* 넓은 화면에서 사이드바를 접으면 숨긴다 (상단의 버튼으로 다시 연다) */
body.sidebar-collapsed .sidebar {
  display: none;
}

/* ── 메인 영역 ──────────────────────────────── */
.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
}

/* 사이드바 여는 버튼: 사이드바가 보이면 숨김 (접었을 때와 휴대폰에서만 보인다) */
.menu-btn {
  display: none;
}
body.sidebar-collapsed .menu-btn {
  display: inline-flex;
}

.chat-title {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer; /* 눌러서 제목 바꾸기 */
}

/* 상단 바 오른쪽의 사용량 표시 */
.stats {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.stat {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12px;
  color: var(--text-muted);
  background: white;
  white-space: nowrap;
}
.stat b {
  color: var(--text);
  font-weight: 600;
}
.stat-btn:hover {
  border-color: var(--accent);
}

/* 컨텍스트 게이지 막대 */
.gauge {
  width: 50px;
  height: 6px;
  border-radius: 3px;
  background: #ececec;
  overflow: hidden;
}
.gauge-fill {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 0.3s;
}

/* AI 답변 아래 "모델 · 토큰 · 비용" 줄 */
.usage-line {
  margin-top: 6px;
  font-size: 11px;
  color: var(--text-muted);
}

/* ── 설정 창 ────────────────────────────────── */
.settings-dialog {
  width: min(760px, calc(100vw - 32px));
  height: min(640px, calc(100vh - 64px));
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--bg);
  color: var(--text);
}
.settings-dialog::backdrop {
  background: rgba(0, 0, 0, 0.3);
}

.dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.dialog-header h2 {
  margin: 0;
  font-weight: 600;
  font-size: 20px;
}
.dialog-close {
  border: none;
  background: none;
  font-size: 18px;
  color: var(--text-muted);
}

.card {
  padding: 12px 14px;
  margin-bottom: 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: white;
}
.card h3 {
  margin: 0 0 8px;
  font-size: 14px;
}
.card .row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 0;
  font-size: 13px;
}
.card .row {
  align-items: center;
}
.card .row span {
  color: var(--text-muted);
}
/* 설정 창의 선택 상자 */
.card .row select {
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  font: inherit;
  font-weight: 600;
  color: var(--text);
}

/* 콘솔(잔액 확인 · 충전) 바로가기 버튼 */
.billing-link {
  display: inline-block;
  margin-top: 8px;
  padding: 6px 12px;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  font-size: 13px;
  text-decoration: none;
}
.billing-link:hover {
  opacity: 0.9;
}

.dialog-note {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.6;
  margin: 4px 0 0;
}

/* ── 메시지 ─────────────────────────────────── */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px;
}

.messages > * {
  max-width: 760px;
  margin-left: auto;
  margin-right: auto;
}

.welcome {
  text-align: center;
}
.welcome h2 {
  font-weight: 500;
  font-size: 28px;
  margin: 0 0 8px;
}
.welcome p {
  margin: 0;
  color: var(--text-muted);
  font-size: 15px;
}

/* 첫 화면(대화가 없을 때): 인사말과 입력창을 화면 가운데에 함께 둔다 */
.main.is-empty .messages {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding-bottom: 20px;
}
.main.is-empty .composer {
  margin-bottom: 32vh;
}

.message {
  margin-bottom: 16px;
}

/* 내 메시지: 오른쪽 회색 말풍선 */
.message.user {
  display: flex;
  justify-content: flex-end;
}
.message.user .body {
  max-width: 80%;
  padding: 10px 18px;
  border-radius: 22px;
  background: var(--user-bubble);
  white-space: pre-wrap;
  word-break: break-word;
}

/* AI 메시지: 참가자 색으로 테두리·바탕을 살짝 칠한 카드 + 이름표
   → 누가 말했는지 한눈에 보이게 한다 */
.message.ai {
  padding: 12px 16px 12px 14px;
  border-left: 4px solid var(--who);
  border-radius: 4px 14px 14px 4px;
  background: color-mix(in srgb, var(--who) 6%, white);
}
.message .name {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 8px;
}
.message .avatar {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 13px;
  font-weight: 700;
}
/* 이름 옆 모델 표시 (예: Opus 5.5) */
.model-tag {
  padding: 1px 8px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--who) 14%, white);
  color: color-mix(in srgb, var(--who) 70%, black);
  font-size: 11px;
  font-weight: 500;
}
/* AI 참가자: 참가자마다 다른 색(--who)으로 칠한다 */
.message.ai .avatar {
  background: var(--who);
}
.message.error .avatar {
  background: #c44;
}
.message.error .name {
  color: #a33;
}
.message.ai .name {
  color: var(--who);
}

.message.ai .body {
  line-height: 1.7;
  word-break: break-word;
}

.message.error .body {
  padding: 10px 14px;
  border-radius: 10px;
  background: #fdecec;
  color: #a33;
}

/* 대화 사이의 안내 문구 (자동 압축 중 등) */
.system-note {
  margin: 0 auto 20px;
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
}

/* "여기까지 요약했어요" 구분선 (누르면 요약이 펼쳐진다) */
.summary-note {
  margin: 4px auto 24px;
  padding: 8px 14px;
  border: 1px dashed var(--border);
  border-radius: 10px;
  background: #f5f5f5;
  font-size: 13px;
}
.summary-note summary {
  cursor: pointer;
  color: var(--text-muted);
}
.summary-note .body {
  margin-top: 8px;
  line-height: 1.6;
}

/* 답변을 기다리는 동안 깜빡이는 점 */
.typing::after {
  content: "●";
  color: var(--text-muted);
  animation: blink 1s infinite;
}
@keyframes blink {
  50% { opacity: 0.2; }
}

/* 마크다운으로 만들어진 요소들 */
.body p {
  margin: 0 0 10px;
}
.body p:last-child {
  margin-bottom: 0;
}
.body ul,
.body ol {
  padding-left: 22px;
  margin: 6px 0 10px;
}
.body code {
  background: #f0f0f0;
  padding: 1px 5px;
  border-radius: 4px;
  font-family: Consolas, monospace;
  font-size: 0.9em;
}
.body pre {
  background: #2b2a27;
  color: #f5f4ef;
  padding: 12px 14px;
  border-radius: 8px;
  overflow-x: auto;
}
.body pre code {
  background: none;
  padding: 0;
  color: inherit;
}
/* 강조: 굵은 글씨는 진하게, 살짝 형광펜처럼 */
.body strong {
  font-weight: 700;
  color: var(--text);
  /* 형광펜: 참가자 색을 옅게 섞어서 */
  background: linear-gradient(transparent 60%, color-mix(in srgb, var(--who, #c96442) 22%, transparent) 60%);
}

/* 제목 */
.body h1,
.body h2,
.body h3,
.body h4 {
  margin: 14px 0 6px;
  line-height: 1.4;
}
.body h1 { font-size: 1.25em; }
.body h2 { font-size: 1.15em; }
.body h3,
.body h4 { font-size: 1.05em; }
.body > :first-child {
  margin-top: 0;
}

.body li {
  margin: 3px 0;
}

/* 인용 */
.body blockquote {
  margin: 8px 0;
  padding: 6px 12px;
  border-left: 3px solid var(--border);
  color: var(--text-muted);
  background: #f5f5f5;
  border-radius: 0 8px 8px 0;
}

.body hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 14px 0;
}

/* 표: 머리줄 색, 줄무늬, 둥근 모서리. 넓으면 옆으로 스크롤 */
.body table {
  display: block;
  max-width: 100%;
  overflow-x: auto;
  border-collapse: separate;
  border-spacing: 0;
  margin: 10px 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 0.95em;
}
.body th,
.body td {
  padding: 7px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}
.body th {
  background: #f0f0f0;
  font-weight: 600;
  white-space: nowrap;
}
.body tr:nth-child(even) td {
  background: #fafafa;
}
.body tr:last-child td {
  border-bottom: none;
}

/* 그래프와 도표 */
.chart-box {
  position: relative;
  height: 260px;
  margin: 10px 0;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: white;
}
.diagram-box {
  margin: 10px 0;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: white;
  overflow-x: auto;
  text-align: center;
}
/* 쓰는 도중에는 그래프·도표의 재료(JSON, 도표 코드)를 숨긴다. 다 끝나면 그림으로 바뀐다 */
.typing pre:has(> code.language-chart),
.typing pre:has(> code.language-mermaid) {
  display: none;
}
.typing:has(code.language-chart)::after,
.typing:has(code.language-mermaid)::after {
  content: " 📊 그리는 중…";
  animation: none;
  color: var(--text-muted);
  font-size: 0.9em;
}

/* ── 입력창 ─────────────────────────────────── */
.composer {
  padding: 0 20px 12px;
}

/* 길쭉하고 둥근 입력창: [+] [글 쓰는 칸] [보내기] */
.composer-box {
  max-width: 760px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding: 8px 8px 8px 10px;
  border: 1px solid var(--border);
  border-radius: 28px;
  background: white;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
}
.composer-box:focus-within {
  border-color: #cfcfcf;
}

.composer textarea {
  flex: 1;
  align-self: center;
  border: none;
  outline: none;
  resize: none;
  font: inherit;
  font-size: 16px;
  line-height: 1.5;
  max-height: 200px;
  padding: 6px 4px;
  background: transparent;
}

.plus-btn {
  border-radius: 50%;
}

.send-btn {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  font-size: 18px;
}
/* 아무것도 안 썼으면 보내기 버튼을 흐리게 */
.composer-box:has(textarea:placeholder-shown) .send-btn:not(.stop) {
  opacity: 0.25;
}
/* 답변을 받는 중에는 중지 버튼(■)으로 바뀐다 */
.send-btn.stop {
  font-size: 13px;
}

/* 입력창 아래: 참가자 + 예상 비용 + 안내 */
.composer-footer {
  max-width: 760px;
  margin: 8px auto 0;
  display: flex;
  flex-wrap: wrap; /* 좁은 화면에서는 다음 줄로 넘긴다 */
  align-items: center;
  justify-content: center;
  gap: 6px 14px;
  font-size: 12px;
  color: var(--text-muted);
}

.estimate {
  font-size: 11px;
  cursor: help; /* 마우스를 올리면 설명(title)이 보인다 */
}

.composer-hint {
  font-size: 11px;
}

/* ── 좁은 화면(휴대폰): 사이드바를 서랍처럼 ─────── */
@media (max-width: 760px) {
  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 10;
    transform: translateX(-100%);
    transition: transform 0.2s;
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: 2px 0 12px rgba(0, 0, 0, 0.12); /* 열렸을 때만 그림자 (닫혀 있을 때 가장자리에 비치지 않게) */
  }
  /* 휴대폰에서는 접기 상태와 상관없이 서랍으로 쓴다 */
  body.sidebar-collapsed .sidebar {
    display: flex;
  }
  .menu-btn {
    display: inline-flex;
  }
  .main.is-empty .composer {
    margin-bottom: 18vh;
  }
  /* 좁은 화면에서는 이번 달 사용 금액 칩만 남긴다 */
  .stats .stat:not(.stat-btn) {
    display: none;
  }
  .messages,
  .composer {
    padding-left: 16px;
    padding-right: 16px;
  }
}

/* ── 입력창 아래 참가자 표시 ─────────────────── */
.members {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 2px 6px;
  border: none;
  border-radius: 8px;
  background: none;
  color: var(--text-muted);
  font-size: 12px;
}
.members:hover {
  background: var(--hover);
}
.member {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--text);
}
.member::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--who);
}

/* ── 설정 창: 참가자 칸 ─────────────────────── */
.participant {
  padding: 10px;
  margin-bottom: 8px;
  border: 1px solid var(--border);
  border-left: 4px solid var(--who);
  border-radius: 10px;
  background: var(--bg);
}
.participant-head {
  display: flex;
  gap: 6px;
  align-items: center;
}
.participant .avatar {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--who);
  color: white;
  font-size: 12px;
}
.participant input,
.participant select,
.participant textarea {
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: white;
  font: inherit;
  font-size: 13px;
}
.participant input {
  flex: 1;
  min-width: 0;
}
.participant textarea {
  width: 100%;
  margin-top: 6px;
  resize: vertical;
}
.participant-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  margin-top: 6px;
}
.participant-actions button {
  padding: 4px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: white;
  font-size: 13px;
}
.participant-actions button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: white;
}
.participant-actions button.danger:hover:not(:disabled) {
  color: #b33;
  border-color: #e6b3b3;
}
.participant-actions button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
/* 고치는 중인데 아직 저장 안 한 칸 */
.participant.editing {
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--who) 35%, transparent);
}
.card .hint {
  margin: 6px 0 0;
  font-size: 12px;
  color: var(--text-muted);
}

/* ── 휴대폰 크기 다듬기 ─────────────────────── */
@media (max-width: 760px) {
  .welcome h2 {
    font-size: 24px;
  }
  /* 휴대폰은 Enter 가 줄바꿈이라 안내 문구가 필요 없다 */
  .composer-hint {
    display: none;
  }
  .settings-dialog {
    padding: 14px;
  }
  /* 참가자 칸: 이름과 모델을 두 줄로 */
  .participant-head {
    flex-wrap: wrap;
  }
  .participant-head input {
    flex: 1 1 calc(100% - 32px);
  }
  .participant-head select {
    width: 100%;
  }
  /* 설정 줄: 이름표와 값이 좁으면 두 줄로 */
  .card .row {
    flex-wrap: wrap;
  }
  /* 글자를 16px 아래로 하면 아이폰이 입력할 때 화면을 확대해 버린다 */
  .composer textarea,
  .participant input,
  .participant textarea {
    font-size: 16px;
  }
}

/* ── 설정 창: 참가자의 서비스·모델 줄 ───────── */
.participant-model {
  display: flex;
  gap: 6px;
  margin-top: 6px;
}
.participant-model select[data-field="provider"] {
  flex-shrink: 0;
}
.model-field {
  flex: 1;
  display: flex;
  gap: 6px;
  min-width: 0;
}
.model-field select,
.model-field input {
  flex: 1;
  min-width: 0;
}
.model-field button,
.provider-key button,
.provider-add button {
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: white;
  font-size: 13px;
  white-space: nowrap;
}

/* ── 설정 창: AI 서비스 카드 ─────────────────── */
.provider-row {
  padding: 8px 0;
  border-top: 1px dashed var(--border);
}
.provider-top {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 13px;
}
.badge {
  padding: 1px 8px;
  border-radius: 999px;
  background: #f0f0f0;
  color: var(--text-muted);
  font-size: 11px;
}
.badge.ok {
  background: #dcefe6;
  color: #2f7d65;
}
.provider-top .links {
  margin-left: auto;
  display: flex;
  gap: 10px;
  font-size: 12px;
}
.provider-top .links a {
  color: var(--accent);
  text-decoration: none;
}
.provider-key {
  display: flex;
  gap: 6px;
  margin-top: 6px;
}
.provider-key input,
.provider-add input {
  flex: 1;
  min-width: 0;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  font-size: 13px;
}
.provider-add {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  font-size: 13px;
}
.provider-add button.primary,
.provider-key button.danger {
  align-self: flex-end;
}
.provider-add button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: white;
}
.provider-row.editing,
.provider-add.editing {
  background: #fafafa;
}
@media (max-width: 760px) {
  .participant-model {
    flex-wrap: wrap;
  }
  .participant-model select[data-field="provider"] {
    width: 100%;
  }
  .provider-key input,
  .provider-add input,
  .model-field input {
    font-size: 16px;
  }
}

/* ── 왼쪽 아래 프로필 메뉴 (위로 뜨는 작은 창) ── */
/* 메뉴를 사이드바 기준으로 띄우기 위해. (휴대폰에서는 사이드바가 이미 fixed 라서 넓은 화면에만) */
@media (min-width: 761px) {
  .sidebar {
    position: relative;
  }
}
.profile-menu {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 62px;
  z-index: 20;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: white;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.12);
}
.profile-menu hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 6px 4px;
}
.menu-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
}
.menu-head-text {
  display: flex;
  flex-direction: column;
  font-size: 14px;
}
.menu-head-text small {
  color: var(--text-muted);
  font-size: 12px;
}
.menu-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: none;
  border-radius: 8px;
  background: none;
  color: var(--text);
  text-align: left;
  font-size: 14px;
}
.menu-item:hover {
  background: var(--hover);
}

/* ── 설정 창: 왼쪽 탭 + 오른쪽 내용 ─────────── */
.settings-dialog[open] {
  display: flex;
  flex-direction: column;
}
.settings-layout {
  flex: 1;
  min-height: 0;
  display: flex;
  gap: 16px;
}
.settings-tabs {
  width: 190px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.settings-tab {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: none;
  border-radius: 8px;
  background: none;
  color: var(--text);
  text-align: left;
  font-size: 14px;
  white-space: nowrap;
}
.settings-tab:hover {
  background: var(--hover);
}
.settings-tab.active {
  background: var(--hover);
  font-weight: 600;
}
#settings-body {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  padding-right: 4px;
}
#settings-body [hidden] {
  display: none;
}
.card.help ul {
  margin: 0 0 12px;
  padding-left: 18px;
  font-size: 13px;
  line-height: 1.8;
}

@media (max-width: 760px) {
  .settings-dialog {
    height: calc(100dvh - 32px);
  }
  /* 휴대폰: 탭을 위쪽에 가로로 (넘치면 옆으로 밀어서) */
  .settings-layout {
    flex-direction: column;
    gap: 10px;
  }
  .settings-tabs {
    width: auto;
    flex-direction: row;
    overflow-x: auto;
  }
  .settings-tab svg {
    display: none;
  }
}

/* 설정 창: 동그라미를 누르면 색 고르기 (색 칸은 동그라미 뒤에 숨겨 둔다) */
.color-pick {
  position: relative;
  cursor: pointer;
}
.color-pick:hover {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--who) 30%, transparent);
}
.color-pick input[type="color"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;   /* 안 보이게 덮어 두고, 누르면 브라우저의 색 고르기 창이 뜬다 */
  cursor: pointer;
  border: none;
  padding: 0;
}

/* 키 붙여넣기 칸 아래: 어느 서비스 키로 보이는지 */
.key-guess {
  margin: 0;
  color: #2f7d65;
}
.key-guess.unsure {
  color: #b8862b;
}
.key-guess:empty {
  display: none;
}
.custom-fields {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.custom-fields[hidden] {
  display: none;
}

/* ── 대기 표시: 질문하면 참가자 AI마다 칩 하나 ──
   대기(흐리게) → 생각 중(점이 통통) → 말하는 중 → 패스(더 흐리게) */
.round-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 4px auto 16px; /* 가운데 정렬은 .messages > * 가 맡는다 (좌우 auto 를 지우면 왼쪽에 붙는다) */
}
.rb-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px 4px 4px;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--who) 25%, white);
  background: color-mix(in srgb, var(--who) 7%, white);
  font-size: 12px;
  color: #555;
  transition: opacity 0.2s;
}
.rb-chip .avatar {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--who);
  color: white;
  font-size: 11px;
  font-weight: 700;
}
.rb-name {
  font-weight: 600;
  color: color-mix(in srgb, var(--who) 70%, black);
}
.rb-chip .dots {
  display: inline-flex;
  gap: 3px;
}
.rb-chip .dots i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--who);
  opacity: 0.35;
}
.rb-chip[data-state="waiting"] {
  opacity: 0.65;
}
.rb-chip[data-state="waiting"] .dots i {
  animation: rb-pulse 1.6s infinite ease-in-out;
}
.rb-chip[data-state="thinking"] {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--who) 18%, transparent);
}
.rb-chip[data-state="thinking"] .dots i {
  opacity: 1;
  animation: rb-bounce 1s infinite ease-in-out;
}
.rb-chip .dots i:nth-child(2) { animation-delay: 0.15s; }
.rb-chip .dots i:nth-child(3) { animation-delay: 0.3s; }
.rb-chip[data-state="speaking"] .dots,
.rb-chip[data-state="passed"] .dots {
  display: none;
}
.rb-chip[data-state="passed"] {
  opacity: 0.4;
}
@keyframes rb-bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-4px); }
}
@keyframes rb-pulse {
  0%, 100% { opacity: 0.2; }
  50% { opacity: 0.6; }
}

/* ── 관리자만 보이는 메뉴 (실제로 막는 건 서버) ── */
body:not(.is-admin) .admin-only {
  display: none !important;
}

/* ── 로그인 창 ── */
.login-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: var(--bg);
}
.login-screen[hidden] {
  display: none;
}
.login-box {
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.login-box h1 {
  margin: 0;
  font-size: 26px;
  text-align: center;
}
.login-box p {
  margin: 0 0 6px;
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
}
.login-box input {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  font: inherit;
}
.login-box button {
  padding: 12px;
  border-radius: 12px;
  font: inherit;
  font-weight: 600;
}
.login-error {
  color: #c0392b !important;
  min-height: 1em;
}

/* ── 사용자 관리, 내 암호 ── */
.user-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.user-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.user-info small {
  color: var(--text-muted);
  font-size: 12px;
}
.user-add,
.account-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.user-add {
  margin-top: 14px;
}
.user-add input,
.account-form input {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font: inherit;
}
.check {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
}
