/* ─── Gemma Desk — Claude 스타일 테마 ─── */
:root {
  --bg: #F5F4EF;
  --bg-panel: #EFEDE6;
  --bg-sidebar: #EBE8E0;
  --bg-input: #FFFFFF;
  --bg-user-bubble: #E8E5DC;
  --bg-hover: #E3E0D6;
  --bg-code: #F0EFE9;
  --text: #29261F;
  --text-soft: #6B675E;
  --text-faint: #9B968A;
  --border: #DAD6CA;
  --accent: #C15F3C;
  --accent-hover: #A94F2F;
  --accent-soft: #F0DED5;
  --danger: #B4433A;
  --radius: 14px;
  --serif: "Source Serif Pro", Georgia, "Noto Serif KR", "Batang", serif;
  --sans: "Segoe UI", "Malgun Gothic", "Apple SD Gothic Neo", sans-serif;
  --mono: "Cascadia Code", Consolas, "D2Coding", monospace;

  /* 유동 레이아웃 스케일 — 기기·창 크기에 따라 매끄럽게 변한다.
     고정 px 대신 clamp 를 쓰면 소형폰~초광폭 사이에 끊김 없이 대응된다. */
  /* 기준점: 1280px 데스크톱에서 기존 고정값(15px / 264px / 780px)과 정확히 일치하도록
     계수를 맞췄다. 여기서부터 작은 화면은 줄고 넓은 화면은 늘어난다. */
  --fs-base: clamp(14px, 0.18vw + 12.7px, 16px);
  --sidebar-w: clamp(200px, 20.6vw, 300px);
  --content-max: clamp(640px, 61vw, 1080px);
  --pad-page: clamp(12px, 1.8vw, 24px);
  --pad-top: clamp(14px, 2.4vw, 32px);
}

/* 업데이트 버튼은 설치본 빌드번호 바로 왼쪽에 둔다. */
.app-update { border: 1px solid var(--accent, #947553); border-radius: 6px; padding: 3px 6px;
  font-size: 11px; white-space: nowrap; color: inherit; background: transparent; cursor: pointer; }
.app-update:disabled { cursor: wait; opacity: .65; }
[data-theme="dark"] {
  --bg: #262624;
  --bg-panel: #21201E;
  --bg-sidebar: #1C1B19;
  --bg-input: #30302D;
  --bg-user-bubble: #34322E;
  --bg-hover: #383632;
  --bg-code: #1F1E1C;
  --text: #EDEAE3;
  --text-soft: #A8A398;
  --text-faint: #736F66;
  --border: #3E3C37;
  --accent: #D97757;
  --accent-hover: #E28B6D;
  --accent-soft: #4A342B;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  font-size: var(--fs-base);
  overflow: hidden;
  /* 기본적으로 UI는 드래그 선택 안 됨(앱 느낌) — 단, 대화 내용은 아래에서 선택 허용 */
  user-select: none;
  -webkit-user-select: none;
}
/* 출력/입력 텍스트는 드래그로 선택·복사 가능하게 */
.msg-body, .msg-user .msg-body, .step-content, .msg-atts, #input,
.edit-area, input, textarea {
  user-select: text;
  -webkit-user-select: text;
  cursor: auto;
}
.msg-body { cursor: text; }
/* 모바일 브라우저는 주소창·툴바가 보일 때 100vh 가 실제 가시 높이보다 크다.
   그러면 가로모드에서 입력창과 전송 버튼이 툴바 아래로 밀린다.
   dvh(동적 뷰포트 높이)를 쓰되, 미지원 브라우저를 위해 vh 를 먼저 둔다. */
#app { display: flex; height: 100vh; height: 100dvh; }
.hidden { display: none !important; }
button { cursor: pointer; font-family: inherit; }

/* ─── 사이드바 ─── */
#sidebar {
  width: var(--sidebar-w); min-width: var(--sidebar-w);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 14px 10px;
}
.sidebar-top { padding: 4px 6px 14px; }
.brand { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; }
.brand-mark { color: var(--accent); font-size: 20px; }
.brand-name { font-family: var(--serif); font-size: 17px; font-weight: 600; letter-spacing: .2px; }
.btn-new {
  width: 100%; padding: 9px 12px;
  background: var(--accent); color: #fff;
  border: none; border-radius: 10px;
  font-size: 14px; font-weight: 600;
  transition: background .15s;
}
.btn-new:hover { background: var(--accent-hover); }
.sidebar-label {
  font-size: 11px; font-weight: 700; letter-spacing: .8px;
  color: var(--text-faint); text-transform: uppercase;
  padding: 6px 10px;
}
#conv-list { flex: 1; overflow-y: auto; }
.conv-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 10px; border-radius: 9px;
  font-size: 13.5px; color: var(--text-soft);
  cursor: pointer; margin-bottom: 2px;
  transition: background .12s;
}
.conv-item:hover { background: var(--bg-hover); }
.conv-item.active { background: var(--bg-hover); color: var(--text); font-weight: 600; }
.conv-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.conv-menu {
  background: none; border: none; color: var(--text-faint);
  font-size: 18px; line-height: 1; padding: 0 6px; border-radius: 5px;
  opacity: 0; transition: opacity .12s, background .12s;
}
.conv-item:hover .conv-menu, .conv-item.active .conv-menu { opacity: 1; }
.conv-menu:hover { color: var(--text); background: var(--bg-panel); }
/* ⋯ 팝업 메뉴 */
.conv-popup {
  position: fixed; z-index: 200; min-width: 150px;
  background: var(--bg-input); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 8px 28px rgba(0,0,0,.28); padding: 5px; overflow: hidden;
}
.conv-popup-item {
  display: block; width: 100%; text-align: left;
  background: none; border: none; color: var(--text);
  font-size: 13.5px; padding: 8px 12px; border-radius: 7px; font-family: inherit;
}
.conv-popup-item:hover { background: var(--bg-hover); }
/* 입력 다이얼로그 */
.modal-backdrop-simple {
  position: fixed; inset: 0; z-index: 210; background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center;
}
.prompt-box {
  background: var(--bg-input); border: 1px solid var(--border); border-radius: 14px;
  padding: 20px 22px; width: min(380px, 90vw);
}
.prompt-label { font-size: 14px; color: var(--text-soft); margin-bottom: 10px; }
.prompt-input {
  width: 100%; padding: 9px 12px; background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 9px; font-family: inherit; font-size: 14px;
}
.prompt-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.sidebar-bottom { display: flex; align-items: center; gap: 6px; padding-top: 10px; border-top: 1px solid var(--border); }
.ghost-btn {
  flex: 1; padding: 8px; background: none;
  border: none; border-radius: 8px;
  color: var(--text-soft); font-size: 13px;
}
.ghost-btn:hover { background: var(--bg-hover); }
/* 계정 버튼 (왼쪽, Claude 스타일) */
.account-btn {
  flex: 1; display: flex; align-items: center; gap: 8px;
  padding: 7px 9px; background: none; border: none; border-radius: 9px;
  color: var(--text); font-size: 13.5px; font-family: inherit;
  overflow: hidden; text-align: left;
}
.account-btn:hover { background: var(--bg-hover); }
.account-avatar {
  width: 24px; height: 24px; min-width: 24px; border-radius: 50%;
  background: var(--accent); color: #fff; font-size: 13px;
  display: flex; align-items: center; justify-content: center;
}
#account-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* 톱니(설정) 아이콘만 — 오른쪽 */
.icon-only-btn {
  width: 36px; min-width: 36px; height: 36px; background: none; border: none;
  border-radius: 9px; color: var(--text-soft); font-size: 17px;
}
.icon-only-btn:hover { background: var(--bg-hover); color: var(--text); }

/* ─── 메인 ─── */
#main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

#welcome { flex: 1; display: flex; align-items: center; justify-content: center; }
.welcome-inner { text-align: center; padding: 0 24px; }
.welcome-mark { font-size: 44px; color: var(--accent); margin-bottom: 18px; }
#welcome h1 {
  font-family: var(--serif); font-weight: 500;
  font-size: 34px; margin-bottom: 14px; letter-spacing: -.3px;
}
.welcome-sub { color: var(--text-soft); font-size: 15px; line-height: 1.7; }

#chat { flex: 1; overflow-y: auto; }
#messages { max-width: var(--content-max); margin: 0 auto; padding: var(--pad-top) var(--pad-page) 20px; }

/* 넓은 표·이미지가 레이아웃을 밀어내지 않게 한다.
   body 가 overflow:hidden 이라 밀려난 내용은 스크롤이 아니라 잘려서 아예 안 보인다. */
.msg-body table { display: block; width: max-content; max-width: 100%; overflow-x: auto; }
.msg-body img, .msg-body video { max-width: 100%; height: auto; }

.msg { margin-bottom: 26px; position: relative; }
.msg-copy {
  position: absolute; top: -22px; right: 0;
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: 7px; padding: 3px 9px;
  font-size: 11.5px; color: var(--text-soft);
  opacity: 0; transition: opacity .15s; z-index: 5;
}
.msg:hover .msg-copy { opacity: 1; }
.msg-copy:hover { color: var(--text); border-color: var(--accent); }
.msg-user { display: flex; justify-content: flex-end; }
.msg-user .msg-body {
  background: var(--bg-user-bubble);
  border-radius: var(--radius);
  padding: 12px 16px;
  max-width: 100%;          /* 폭 상한은 부모(col 82%)가 담당 — 이중 축소 방지 */
  width: fit-content;       /* 항상 내용 기준 폭 (min-content로 좁게 붕괴하는 버그 방지) */
  margin-left: auto;        /* 우측 정렬 유지 */
  white-space: pre-wrap;
  word-break: keep-all;     /* 한글 단어 중간('아/니오')에서 줄바꿈 금지 */
  overflow-wrap: anywhere;  /* 공백 없는 초장문만 예외적으로 줄바꿈 */
  line-height: 1.65;
}
.msg-assistant .msg-head {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 6px;
}
.msg-assistant .msg-avatar { color: var(--accent); font-size: 15px; }
.msg-assistant .msg-model { font-size: 12px; color: var(--text-faint); }
.msg-assistant .msg-model.has-detail { cursor: pointer; }
.msg-assistant .msg-model.has-detail:hover { color: var(--text-soft); }
.msg-detail-hint { color: var(--accent); font-size: 11px; margin-left: 2px; }
.msg-assistant .msg-body { line-height: 1.7; overflow-wrap: break-word; }
/* AI 답변 하단 복사 버튼 (항상 보임) */
.msg-foot { margin-top: 8px; display: flex; gap: 8px; }
.msg-foot-btn {
  background: transparent; border: 1px solid var(--border);
  border-radius: 7px; padding: 4px 12px; font-size: 12px;
  color: var(--text-soft); cursor: pointer; transition: all .15s;
}
.msg-foot-btn:hover { color: var(--text); border-color: var(--accent); background: var(--bg-input); }

/* 마크다운 렌더링 */
.msg-body h1, .msg-body h2, .msg-body h3 {
  font-family: var(--serif); font-weight: 600;
  margin: 18px 0 8px; line-height: 1.35;
}
.msg-body h1 { font-size: 22px; } .msg-body h2 { font-size: 19px; } .msg-body h3 { font-size: 16.5px; }
.msg-body p { margin: 8px 0; }
.msg-body ul, .msg-body ol { margin: 8px 0 8px 22px; }
.msg-body li { margin: 3px 0; }
.msg-body a { color: var(--accent); }
.msg-body blockquote {
  border-left: 3px solid var(--accent);
  padding: 2px 14px; margin: 10px 0;
  color: var(--text-soft);
}
.msg-body table { border-collapse: collapse; margin: 12px 0; font-size: 14px; }
.msg-body th, .msg-body td { border: 1px solid var(--border); padding: 6px 12px; }
.msg-body th { background: var(--bg-panel); }
.msg-body code { font-family: var(--mono); font-size: 13px; background: var(--bg-code); padding: 2px 5px; border-radius: 5px; }
.msg-body pre {
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin: 12px 0; overflow: hidden;
}
.msg-body pre code { display: block; padding: 14px 16px; overflow-x: auto; background: none; }
.code-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 12px; color: var(--text-faint);
  background: var(--bg-panel);
}
.copy-btn {
  background: none; border: none; color: var(--text-soft);
  font-size: 12px; padding: 2px 8px; border-radius: 5px;
}
.copy-btn:hover { background: var(--bg-hover); }

/* 첨부 뱃지 (메시지 안) */
.msg-atts { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; justify-content: flex-end; }
.att-badge {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--bg-panel); border: 1px solid var(--border);
  border-radius: 8px; padding: 4px 10px; font-size: 12.5px; color: var(--text-soft);
}
.att-thumb { width: 42px; height: 42px; object-fit: cover; border-radius: 7px; border: 1px solid var(--border); }

/* 메시지 수정/삭제 도구 */
.msg-tools { display: flex; gap: 6px; justify-content: flex-end; margin-top: 5px; }
.msg-tool {
  background: none; border: 1px solid var(--border); border-radius: 7px;
  padding: 3px 10px; font-size: 11.5px; color: var(--text-soft);
  opacity: 0; transition: opacity .12s;
}
.msg-user:hover .msg-tool { opacity: 1; }
/* 긴 사용자 메시지 자동 접기 */
.msg-user .msg-body.clamped {
  max-height: 150px; overflow: hidden;
  -webkit-mask-image: linear-gradient(180deg, #000 60%, transparent 98%);
  mask-image: linear-gradient(180deg, #000 60%, transparent 98%);
}
.msg-expand {
  display: block; margin-left: auto; margin-top: 2px;
  background: none; border: none; cursor: pointer;
  color: var(--text-faint); font-size: 12px; padding: 2px 6px;
}
.msg-expand:hover { color: var(--accent); }
.msg-tool:hover { color: var(--text); border-color: var(--accent); }
.edit-area {
  width: 100%; min-height: 150px; padding: 12px 14px;
  background: var(--bg-input); color: var(--text);
  border: 1px solid var(--accent); border-radius: 10px;
  font-family: inherit; font-size: 15px; line-height: 1.6; resize: vertical;
}
/* 편집 중인 말풍선은 넓게 — 좁은 버블 폭에 갇히지 않게 */
.msg-user .edit-area { min-width: min(560px, 78vw); }

/* 피드백 버튼 */
.fb-box { margin-left: 4px; }
.fb-btn {
  background: none; border: none; font-size: 12px;
  padding: 2px 4px; border-radius: 5px; opacity: .45;
  transition: opacity .12s;
}
.fb-btn:hover { opacity: 1; background: var(--bg-hover); }
.fb-btn.picked { opacity: 1; }
.fb-btn:disabled { cursor: default; }
.fb-btn:disabled:not(.picked) { opacity: .2; }
.regen-btn { font-size: 13px; opacity: .5; }
.regen-btn:disabled { opacity: .5 !important; cursor: pointer; }
/* 재생성 피드백 입력 */
.regen-ask {
  margin-top: 10px; padding: 12px 14px;
  background: var(--bg-panel); border: 1px solid var(--border); border-radius: 10px;
}
.regen-ask-q { font-size: 13px; color: var(--text-soft); margin-bottom: 8px; }
.regen-ask .edit-area { width: 100%; margin-bottom: 8px; }

/* 협력 모드 작업 과정 */
.steps { margin-bottom: 10px; }
/* 작업 과정 접기/펼치기 */
/* 작업과정 래퍼: 단계가 있을 때만 표시 (has-steps 클래스로 제어 — 모든 WebView 호환) */
.steps-wrap { margin-bottom: 10px; display: none; }
.steps-wrap.has-steps { display: block; }
.steps-wrap.collapsed > .steps { display: none; }
.steps-wrap > .steps { margin-top: 6px; margin-bottom: 0; }
.steps-toggle {
  background: var(--bg-panel); border: 1px solid var(--border); border-radius: 8px;
  padding: 4px 12px; font-size: 12.5px; color: var(--text-soft);
  cursor: pointer; font-family: inherit;
}
.steps-toggle:hover { border-color: var(--accent); color: var(--text); }
.steps-toggle .arr { margin-left: 5px; font-size: 10px; }
.att-thumb { cursor: zoom-in; }
.step {
  border: 1px solid var(--border); border-radius: 10px;
  margin-bottom: 6px; overflow: hidden; background: var(--bg-panel);
}
.step summary {
  padding: 8px 12px; cursor: pointer; font-size: 13px;
  color: var(--text-soft); display: flex; align-items: center; gap: 8px;
  list-style: none;
}
.step summary::-webkit-details-marker { display: none; }
/* 단계 설명 — 무엇을 왜 하는지. 펼치지 않아도 보이도록 summary 안에서 줄바꿈시킨다.
   (summary 가 flex 라서 flex-basis:100% 로 다음 줄에 떨어뜨린다) */
.step summary { flex-wrap: wrap; }
.step-note {
  flex-basis: 100%; width: 100%;
  margin-top: 3px; padding-left: 20px;
  font-size: 12.5px; line-height: 1.55; color: var(--text-faint);
  word-break: keep-all; overflow-wrap: anywhere;
}
.step .spinner { display: inline-block; width: 12px; height: 12px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.step .step-model { color: var(--text-faint); font-size: 11.5px; margin-left: auto; }
.step-content { padding: 10px 14px; border-top: 1px solid var(--border); font-size: 13.5px; line-height: 1.6; color: var(--text-soft); white-space: pre-wrap; max-height: 260px; overflow-y: auto; }

/* 커서 깜빡임 */
.cursor { display: inline-block; width: 8px; height: 17px; background: var(--accent); vertical-align: text-bottom; animation: blink 1s steps(1) infinite; border-radius: 2px; }
@keyframes blink { 50% { opacity: 0; } }

/* ─── 입력 영역 ─── */
#composer-wrap { max-width: var(--content-max); width: 100%; margin: 0 auto; padding: 8px var(--pad-page) 10px; }
#attach-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: 9px; padding: 5px 10px; font-size: 12.5px;
}
.chip img { width: 26px; height: 26px; object-fit: cover; border-radius: 5px; }
.chip.err { border-color: var(--danger); color: var(--danger); }
.chip button { background: none; border: none; color: var(--text-faint); font-size: 13px; }
.chip button:hover { color: var(--danger); }
.attach-meter { align-self: center; font-size: 11.5px; color: var(--text-faint);
  padding: 2px 8px; border-radius: 999px; background: rgba(255,255,255,.04); }
.attach-meter.warn { color: var(--danger); background: rgba(255,80,80,.12); font-weight: 600; }

#composer {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: 0 2px 14px rgba(0,0,0,.05);
  padding: 12px 14px 10px;
  transition: border-color .15s, box-shadow .15s;
}
#composer:focus-within { border-color: var(--accent); box-shadow: 0 2px 18px rgba(193,95,60,.12); }
.composer-top { display: flex; align-items: flex-end; gap: 8px; }
#input {
  flex: 1; min-width: 0; border: none; outline: none; resize: none;
  background: transparent; color: var(--text);
  font-family: inherit; font-size: 15px; line-height: 1.55;
  max-height: 220px;
}
#input::placeholder { color: var(--text-faint); }
.composer-bar { display: flex; align-items: flex-end; justify-content: space-between; margin-top: 8px; gap: 8px; }
.composer-left { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; min-width: 0; }
.icon-btn {
  background: none; border: none; font-size: 16px;
  padding: 6px 8px; border-radius: 8px; color: var(--text-soft);
}
.icon-btn:hover { background: var(--bg-hover); }
#model-select, .role-select {
  background: var(--bg-panel); color: var(--text-soft);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 5px 8px; font-size: 12.5px; font-family: inherit;
  max-width: 230px;
}
.team-toggle {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12.5px; color: var(--text-soft); cursor: pointer;
  padding: 5px 10px; border-radius: 8px; border: 1.5px solid var(--border);
  user-select: none; transition: border-color .12s, color .12s, background .12s;
}
.team-toggle:hover { background: var(--bg-hover); }
.team-toggle input { display: none; }  /* 체크박스 숨김 — 켜짐은 테두리로 표시 */
.team-toggle.on { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); font-weight: 600; }
/* 스토리·매크로·샘플 버튼: 컴포저 기능 버튼(team-toggle)과 동일 규격(테두리 통일) */
#btn-story, #btn-macro, #btn-samples {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12.5px; color: var(--text-soft); cursor: pointer;
  padding: 5px 10px; border-radius: 8px; border: 1.5px solid var(--border);
  background: none; font-family: inherit;
  transition: border-color .12s, color .12s, background .12s;
}
#btn-story:hover, #btn-macro:hover, #btn-samples:hover { background: var(--bg-hover); border-color: var(--accent); color: var(--accent); }
.send-btn {
  width: 36px; height: 36px;
  background: var(--accent); color: #fff;
  border: none; border-radius: 10px;
  font-size: 17px; font-weight: 700;
  transition: background .15s;
}
.send-btn:hover { background: var(--accent-hover); }
.send-btn:disabled { background: var(--border); cursor: default; }
.send-btn.stop { background: var(--text); font-size: 13px; }
/* 첨부(이미지) 처리 중: 발송 버튼 잠금 + 로딩 표시 */
.send-btn.attaching { background: var(--border); cursor: progress; position: relative; color: transparent; }
.send-btn.attaching::after {
  content: ""; position: absolute; inset: 0; margin: auto; width: 15px; height: 15px;
  border: 2px solid rgba(255,255,255,.35); border-top-color: #fff; border-radius: 50%;
  animation: sendspin .7s linear infinite;
}
@keyframes sendspin { to { transform: rotate(360deg); } }
/* 발송 안내 말풍선 */
#send-tip {
  position: fixed; transform: translate(-50%, -100%);
  background: var(--text); color: var(--bg); font-size: 12.5px; font-weight: 600;
  padding: 7px 12px; border-radius: 10px; white-space: nowrap; z-index: 300;
  box-shadow: 0 4px 16px rgba(0,0,0,.25);
  opacity: 0; pointer-events: none; transition: opacity .15s, transform .15s;
}
#send-tip.show { opacity: 1; transform: translate(-50%, -115%); }
#send-tip::after {
  content: ""; position: absolute; left: 50%; bottom: -5px; transform: translateX(-50%);
  border: 5px solid transparent; border-top-color: var(--text); border-bottom: 0;
}
.composer-hint { text-align: center; font-size: 11.5px; color: var(--text-faint); margin-top: 7px; }

/* ─── 설정 모달 ─── */
#modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.4);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
#settings-modal {
  background: var(--bg); border-radius: 16px;
  width: min(620px, 92vw); max-height: 86vh;
  display: flex; flex-direction: column;
  box-shadow: 0 18px 60px rgba(0,0,0,.3);
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px 10px;
}
.modal-head h2 { font-family: var(--serif); font-size: 21px; font-weight: 600; }
.modal-body { padding: 4px 22px; overflow-y: auto; }
.modal-body h3 { font-size: 14px; margin: 18px 0 8px; }
.setting-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
/* 폴더 열기 목록 — 버튼 폭을 맞춰 설명이 한 줄에서 시작하게 */
.folder-list .folder-row > .small-btn { min-width: 148px; text-align: left; }
.setting-row label { width: 120px; min-width: 120px; font-size: 13.5px; color: var(--text-soft); }
.setting-row input[type=text], .setting-row input[type=password] {
  flex: 1; padding: 8px 12px;
  background: var(--bg-input); color: var(--text);
  border: 1px solid var(--border); border-radius: 9px;
  font-family: inherit; font-size: 13.5px;
}
.setting-row input[type=range] { flex: 1; accent-color: var(--accent); }
.setting-row select { flex: 1; }
#user-profile, #profile-text {
  width: 100%; padding: 10px 12px;
  background: var(--bg-input); color: var(--text);
  border: 1px solid var(--border); border-radius: 9px;
  font-family: inherit; font-size: 13.5px; resize: vertical;
  box-sizing: border-box;
}
.small-btn, .primary-btn {
  padding: 8px 16px; border: none; border-radius: 9px;
  background: var(--accent); color: #fff; font-size: 13.5px; font-weight: 600;
}
.small-btn:hover, .primary-btn:hover { background: var(--accent-hover); }
.modal-foot { padding: 14px 22px 18px; text-align: right; }
.muted { color: var(--text-faint); font-weight: 400; }
.small { font-size: 12px; margin: 4px 0 8px; }
.progress-track { height: 8px; background: var(--bg-panel); border-radius: 5px; overflow: hidden; margin: 8px 0 4px; }
.progress-bar { height: 100%; width: 0; background: var(--accent); transition: width .3s; }
.progress-status { font-size: 12px; color: var(--text-soft); }

.plugin-settings { margin-top: 18px; }
.plugin-settings-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.plugin-settings-head h3 { margin-top: 0; }
.plugin-list { display: grid; gap: 8px; }
.plugin-card {
  display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 10px;
  align-items: center; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 10px; background: var(--bg-panel);
}
.plugin-card-main { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.plugin-card-main strong { overflow-wrap: anywhere; color: var(--text); }
.plugin-badges { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px; }
.plugin-badge { padding: 2px 7px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: 11px; }
.plugin-card input[type=checkbox] { accent-color: var(--accent); width: 18px; height: 18px; }
@media (max-width: 560px) {
  .plugin-settings-head { flex-direction: column; }
  .plugin-card { grid-template-columns: minmax(0, 1fr) auto; }
  .plugin-badges { grid-column: 1 / -1; grid-row: 2; justify-content: flex-start; }
}

/* 브랜드/웰컴 아이콘 */
.brand-icon { width: 24px; height: 24px; border-radius: 6px; }
.brand-ver { font-size: 11px; color: var(--text-faint); margin-left: auto; align-self: flex-end; padding-bottom: 2px; }
.welcome-icon { width: 76px; height: 76px; border-radius: 18px; margin-bottom: 18px; box-shadow: 0 6px 24px rgba(43,108,238,.25); }

/* PC 모드: 명령 실행 승인 카드 */
.exec-card {
  border: 1.5px solid var(--accent);
  border-radius: 12px; margin: 8px 0;
  background: var(--bg-panel); overflow: hidden;
}
.exec-head {
  padding: 8px 14px; font-size: 13px; font-weight: 600;
  color: var(--accent); background: var(--accent-soft);
}
.exec-card pre {
  margin: 0; padding: 12px 14px;
  font-family: var(--mono); font-size: 13px;
  white-space: pre-wrap; word-break: break-all;
  max-height: 220px; overflow-y: auto;
  background: var(--bg-code);
}
.exec-actions { display: flex; gap: 8px; padding: 10px 14px; }
.deny-btn {
  padding: 8px 16px; border: 1px solid var(--border); border-radius: 9px;
  background: var(--bg-input); color: var(--text-soft); font-size: 13.5px;
}
.deny-btn:hover { border-color: var(--danger); color: var(--danger); }
.exec-done { font-size: 13px; color: var(--text-soft); padding: 4px 0; }

/* 생성된 이미지 */
.gen-images { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px; }
.gen-image {
  max-width: 340px; max-height: 340px;
  border-radius: 12px; border: 1px solid var(--border);
  cursor: zoom-in; box-shadow: 0 3px 14px rgba(0,0,0,.08);
}
/* 지연 로딩 이미지 자리표시 — 로드 전 레이아웃이 흔들리지 않게 최소 크기·배경 */
img.img-lazy {
  background: var(--border) linear-gradient(90deg, transparent, rgba(255,255,255,.12), transparent);
  background-size: 200% 100%; animation: imgshimmer 1.2s infinite;
}
img.att-thumb.img-lazy { min-width: 42px; min-height: 42px; }
img.gen-image.img-lazy { min-width: 180px; min-height: 180px; }
@keyframes imgshimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
.gen-file-btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 11px 15px; border-radius: 12px;
  border: 1px solid var(--accent); background: var(--bg-panel); color: var(--text);
  font: inherit; font-size: 14px; cursor: pointer; max-width: 100%;
}
.gen-file-btn:hover { background: rgba(217,138,61,.1); }
.gen-file-btn .fn { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gen-file-btn em { color: var(--accent); font-style: normal; font-size: 12.5px; white-space: nowrap; }
.gen-video {
  max-width: 480px; width: 100%;
  border-radius: 12px; border: 1px solid var(--border);
  box-shadow: 0 3px 14px rgba(0,0,0,.08);
}
.gen-audio { width: 100%; max-width: 420px; }
#gen-type {
  background: var(--bg-panel); color: var(--text-soft);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 5px 8px; font-size: 12.5px; font-family: inherit;
}

/* 로그인 / 온보딩 화면 */
#login-overlay, #onboard-overlay {
  position: fixed; inset: 0; z-index: 120;   /* 상단 메뉴 버튼(z-index 100)보다 위 */
  background: var(--bg);
  display: flex; justify-content: center;
  overflow-y: auto; padding: 24px 0;
}
/* 로그인/온보딩 중에는 대화용 상단 메뉴(☰)·스크림을 숨긴다 */
body.logged-out #btn-sidebar,
body.logged-out #sidebar-scrim { display: none !important; }
#onboard-box {
  width: min(400px, 90vw); margin: auto;
  display: flex; flex-direction: column; gap: 10px; text-align: center;
}
#onboard-box h2 { font-family: var(--serif); font-size: 24px; font-weight: 600; }
#onboard-box input, #onboard-box select, #onboard-box textarea {
  padding: 11px 14px; background: var(--bg-input); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
  font-family: inherit; font-size: 14px; resize: vertical;
}
#onboard-box input:focus, #onboard-box select:focus, #onboard-box textarea:focus {
  outline: none; border-color: var(--accent);
}
#login-box {
  width: min(380px, 90vw); margin: auto;
  display: flex; flex-direction: column; gap: 10px;
  text-align: center;
}
.login-icon { width: 64px; height: 64px; border-radius: 15px; margin: 0 auto 4px; box-shadow: 0 6px 24px rgba(43,108,238,.25); }
#login-box h2 { font-family: var(--serif); font-size: 26px; font-weight: 600; }
.login-sub { color: var(--text-soft); font-size: 14px; margin-bottom: 8px; }
#login-box input {
  padding: 11px 14px;
  background: var(--bg-input); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
  font-family: inherit; font-size: 14px;
}
#login-box input:focus { outline: none; border-color: var(--accent); }
#login-opts { display: flex; gap: 14px; margin: 2px 0 6px; flex-wrap: wrap; justify-content: center; }
#login-opts label { display: flex; align-items: center; gap: 5px; font-size: 12.5px; color: var(--text-soft); cursor: pointer; }
#login-opts input[type="checkbox"] { width: auto; margin: 0; accent-color: var(--accent); }

/* 유저 관리 (admin) */
.admin-row { display: flex; align-items: center; gap: 8px; padding: 7px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.admin-row:last-child { border-bottom: none; }
.online-dot { width: 8px; height: 8px; border-radius: 50%; background: #22C55E; flex: none; }
.online-dot.off { background: var(--border); }
.online-label { font-size: 11px; color: var(--text-soft); min-width: 34px; }
.admin-name { font-weight: 650; min-width: 88px; }
.admin-meta { color: var(--text-soft); font-size: 12px; flex: 1; }
.admin-row .small-btn { padding: 3px 8px; font-size: 12px; }
#admin-log { max-height: 220px; overflow: auto; border: 1px solid var(--border); border-radius: 8px; padding: 10px; font-size: 11.5px; white-space: pre-wrap; }

/* 생성 엔진 샘플 갤러리 */
#sample-panel {
  border: 1px solid var(--border); border-radius: 14px; background: var(--bg-panel, var(--bg));
  padding: 12px 14px; margin-bottom: 8px; max-height: 46vh; overflow-y: auto;
}
.sample-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.sample-head b { font-size: 14px; }
.sample-head #sample-progress { flex: 1; }
#sample-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 8px; }
.sample-card {
  border: 2px solid var(--border); border-radius: 10px; overflow: hidden; cursor: pointer;
  background: var(--bg); text-align: center; transition: border-color 0.12s;
}
.sample-card:hover { border-color: var(--accent); }
.sample-card.selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.sample-card img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; }
.sample-card .no-thumb {
  width: 100%; aspect-ratio: 1; display: flex; align-items: center; justify-content: center;
  color: var(--text-faint); font-size: 11px; background: var(--bg-user-bubble);
}
.sample-card .sample-label {
  font-size: 11px; font-weight: 650; padding: 4px 4px 1px; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}
.sample-card .sample-desc {
  font-size: 9.5px; color: var(--text-faint); padding: 0 4px 5px; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}
#sample-media video, #sample-media audio { width: 100%; max-width: 480px; border-radius: 10px; margin-top: 4px; }
#gen-engine { max-width: 170px; }
.login-btn { padding: 11px; font-size: 15px; margin-top: 4px; }
.login-error { color: var(--danger); font-size: 13px; }
#otp-setup { padding: 6px 0 2px; }
.otp-guide { font-size: 13px; color: var(--text-soft); line-height: 1.6; margin-bottom: 10px; }
#qrcode { display: flex; justify-content: center; padding: 8px; background: #fff; border-radius: 12px; width: fit-content; margin: 0 auto; border: 1px solid var(--border); }
.otp-secret { font-size: 11.5px; color: var(--text-faint); margin-top: 8px; word-break: break-all; }
.otp-secret code { background: var(--bg-panel); padding: 2px 6px; border-radius: 5px; }
#agent-status { font-size: 11.5px; color: var(--text-faint); padding: 4px 10px; }
#agent-status.off { color: var(--danger); }

/* 코딩 모드 폴더 표시 */
.coder-folder {
  font-size: 12px; color: var(--accent);
  background: var(--accent-soft); border-radius: 7px;
  padding: 4px 9px; max-width: 260px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* 화면 매크로 모달 */
#macro-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.4);
  display: flex; align-items: center; justify-content: center; z-index: 60;
}
#macro-modal {
  background: var(--bg); border-radius: 16px;
  width: min(560px, 92vw); max-height: 86vh;
  display: flex; flex-direction: column;
  box-shadow: 0 18px 60px rgba(0,0,0,.3);
}
.macro-status {
  min-height: 20px; margin: 6px 0 4px; font-size: 13px;
  color: var(--accent); font-weight: 600;
}
.macro-item {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 12px; border: 1px solid var(--border);
  border-radius: 10px; margin-bottom: 6px;
}
.macro-item span { flex: 1; font-size: 13.5px; }

/* 삭제 확인 창 */
#confirm-backdrop {
  position: fixed; inset: 0; z-index: 95;
  background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center;
}
#confirm-box {
  background: var(--bg); border-radius: 14px;
  width: min(360px, 88vw); padding: 22px 22px 18px;
  box-shadow: 0 16px 50px rgba(0,0,0,.35);
}
#confirm-box h3 { font-family: var(--serif); font-size: 17px; margin-bottom: 6px; }
#confirm-desc { font-size: 13px; margin-bottom: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.confirm-actions { display: flex; justify-content: flex-end; gap: 8px; }
.danger-btn {
  padding: 8px 18px; border: none; border-radius: 9px;
  background: var(--danger); color: #fff; font-size: 13.5px; font-weight: 600;
}
.danger-btn:hover { filter: brightness(1.1); }

/* 토스트 */
#toast {
  position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg);
  padding: 10px 20px; border-radius: 10px;
  font-size: 13.5px; z-index: 100;
  box-shadow: 0 6px 24px rgba(0,0,0,.25);
  max-width: 70vw;
}

/* 라이트박스 */
#lightbox {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(0,0,0,.75);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  cursor: zoom-out;
}
#lightbox img { max-width: 92vw; max-height: 84vh; border-radius: 10px; cursor: default; }
#lightbox-download {
  background: var(--accent); color: #fff; border: none;
  padding: 10px 20px; border-radius: 10px; font-size: 14px; font-weight: 600;
  cursor: pointer; font-family: inherit;
}
#lightbox-download:hover { background: var(--accent-hover); }

/* 스크롤바 */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }

/* 사이드바 열기 버튼 (모바일에서만 노출) */
#btn-sidebar { display: none; }
#sidebar-scrim { display: none; }

/* 앱·모바일(웹) 모드에서는 메인 PC 전용 기능 숨김 (매크로·PC작업·코딩·프로그램 삭제) */
html.web-mode .main-pc-only { display: none !important; }

/* ─── 태블릿 (≤1024px): 사이드바 조금 좁게, 여백 축소 ─── */
@media (max-width: 1024px) {
  /* 사이드바 폭은 --sidebar-w(clamp)가 자동으로 줄인다 — 여기서 다시 지정하지 않는다 */
  .msg-user .msg-body, #messages > .msg { max-width: 100%; }
}

/* ─── 태블릿 세로·좁은 창 (≤900px): 사이드바를 더 좁혀 본문 폭을 확보 ─── */
@media (max-width: 900px) {
  :root { --sidebar-w: clamp(180px, 22vw, 220px); }
  .brand-name { font-size: 15px; }
  .sidebar-section { font-size: 10.5px; }
}

/* ─── 모바일 (≤680px): 사이드바를 슬라이드 오버레이로 ─── */
@media (max-width: 680px) {
  #sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; z-index: 120;
    width: 82vw; max-width: 320px; min-width: 0;
    transform: translateX(-100%); transition: transform .22s ease;
    box-shadow: 2px 0 20px rgba(0,0,0,.35);
  }
  #app.sidebar-open #sidebar { transform: translateX(0); }
  #sidebar-scrim {
    display: block; position: fixed; inset: 0; z-index: 110;
    background: rgba(0,0,0,.45); opacity: 0; pointer-events: none; transition: opacity .22s;
  }
  #app.sidebar-open #sidebar-scrim { opacity: 1; pointer-events: auto; }
  /* 상단에 사이드바 열기(☰) 버튼 */
  #btn-sidebar {
    display: flex; align-items: center; justify-content: center;
    position: fixed; top: 10px; left: 10px; z-index: 100;
    width: 40px; height: 40px; border: none; border-radius: 10px;
    background: var(--bg-panel); color: var(--text); font-size: 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,.2);
  }
  #main { padding-top: 4px; }
  #welcome h1 { font-size: 26px; margin-top: 40px; }
  #messages { padding: 56px 12px 12px; }
  /* 입력창 버튼들이 좁은 화면에서 줄바꿈되도록 */
  .composer-bar { flex-wrap: wrap; gap: 6px; }
  .composer-left { flex-wrap: wrap; gap: 6px; }
  .team-toggle span, #model-select { font-size: 12.5px; }
  #settings-modal, #macro-modal { width: 96vw; max-height: 92vh; }
  /* 터치 타깃 키우기 */
  .conv-item { padding: 11px 10px; }
  .conv-menu { opacity: 1; font-size: 20px; }
  .msg-copy, .msg-tool { opacity: 1; }
  .att-thumb { width: 52px; height: 52px; }
  #lightbox-download { padding: 13px 24px; font-size: 15px; }
}

/* ─── 짧은 높이 가로모드 (폰 가로·폴더블 접힘 등) ───
   세로 여백을 줄여 입력창과 전송 버튼이 화면 밖으로 밀려나지 않게 한다. */
@media (orientation: landscape) and (max-height: 520px) {
  #messages { padding-top: 10px; padding-bottom: 8px; }
  .msg { margin-bottom: 16px; }
  .welcome-mark { font-size: clamp(22px, 7vh, 44px); margin-bottom: 6px; }
  #welcome h1 { font-size: clamp(18px, 6vh, 34px); margin-bottom: 6px; margin-top: 0; }
  .welcome-sub { display: none; }
  #composer-wrap { padding-top: 4px; padding-bottom: 6px; }
  #settings-modal, #macro-modal { max-height: 96vh; }
  .modal-body { max-height: 62vh; }
}

/* 터치 기기: 대화목록 메뉴·피드백은 항상 표시, 복사·수정 도구는 말풍선을 한 번 탭했을 때만 */
@media (hover: none) {
  .conv-menu, .fb-box, .msg-atts .att-thumb { opacity: 1 !important; }
  .msg .msg-copy, .msg .msg-tool { opacity: 0; pointer-events: none; }
  .msg.show-tools .msg-copy, .msg.show-tools .msg-tool { opacity: 1 !important; pointer-events: auto; }
}
.brand { cursor: pointer; }
