/* 고객응대 채팅: 손님 위젯(.ahc-*) 과 직원 화면(.sc-*). 색은 site.css 의 --brand, --ink, --line 을 따른다. */

/* ---------- 손님 위젯 ---------- */
.ahc-fab {
  position: fixed; right: 16px; bottom: 16px; z-index: 1040;
  width: 56px; height: 56px; border-radius: 50%; border: 0;
  background: var(--brand); color: #fff; font-size: 1.5rem;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .22); display: grid; place-items: center; cursor: pointer;
}
.ahc-fab:hover { background: var(--brand-dark); }
.ahc-fab:focus-visible { outline: 3px solid rgba(0, 0, 0, .35); outline-offset: 2px; }
.ahc-badge {
  position: absolute; top: -2px; right: -2px; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 10px;
  background: #d93025; color: #fff; font-size: .72rem; font-weight: 600; line-height: 20px; text-align: center;
}
.ahc-tip {
  position: fixed; right: 16px; bottom: 82px; z-index: 1040; max-width: 260px;
  background: #fff; color: var(--ink); border: 1px solid var(--line); border-radius: 12px;
  padding: .6rem 2rem .6rem .8rem; font-size: .88rem; box-shadow: 0 4px 14px rgba(0, 0, 0, .14);
}
.ahc-tip button { position: absolute; top: .3rem; right: .4rem; border: 0; background: none; color: var(--ink-soft); font-size: 1rem; }

.ahc-panel {
  position: fixed; right: 16px; bottom: 84px; z-index: 1045;
  width: 360px; max-width: calc(100vw - 32px); height: min(560px, calc(100vh - 110px));
  display: flex; flex-direction: column; background: #fff; color: var(--ink);
  border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 10px 32px rgba(0, 0, 0, .2); overflow: hidden;
}
.ahc-panel[hidden] { display: none; }
.ahc-head { display: flex; align-items: center; gap: .5rem; padding: .7rem .8rem; background: var(--brand); color: #fff; }
.ahc-title { flex: 1; min-width: 0; font-weight: 600; line-height: 1.2; }
.ahc-title small { display: block; font-weight: 400; font-size: .72rem; opacity: .85; }
.ahc-lang { width: auto; max-width: 8.5rem; font-size: .78rem; padding: .15rem 1.6rem .15rem .4rem; border-radius: 6px; }
.ahc-close { border: 0; background: none; color: #fff; font-size: 1.4rem; line-height: 1; padding: 0 .2rem; }
.ahc-log { flex: 1; overflow-y: auto; padding: .8rem; background: var(--paper-soft); display: flex; flex-direction: column; gap: .5rem; }
.ahc-msg { max-width: 85%; padding: .45rem .7rem; border-radius: 12px; background: #fff; border: 1px solid var(--line); font-size: .9rem; }
.ahc-msg.ahc-me { align-self: flex-end; background: var(--brand); border-color: var(--brand); color: #fff; }
.ahc-msg.ahc-system { align-self: center; max-width: 95%; background: transparent; border: 0; color: var(--ink-soft); font-size: .8rem; text-align: center; }
.ahc-who { display: block; font-size: .7rem; font-weight: 600; color: var(--ink-soft); margin-bottom: .1rem; }
.ahc-text { white-space: pre-wrap; word-break: break-word; }
.ahc-orig { white-space: pre-wrap; word-break: break-word; margin-top: .3rem; padding-top: .3rem; border-top: 1px dashed var(--line); font-size: .8rem; color: var(--ink-soft); }
.ahc-time { display: block; font-size: .65rem; opacity: .6; margin-top: .15rem; text-align: right; }
.ahc-opts { padding: .25rem .8rem 0; font-size: .75rem; color: var(--ink-soft); }
.ahc-form { display: flex; gap: .4rem; padding: .5rem .6rem .6rem; border-top: 1px solid var(--line); }
.ahc-form textarea { flex: 1; resize: none; font-size: .9rem; max-height: 120px; }
.ahc-send { flex: none; width: 42px; border-radius: 50%; border: 0; background: var(--brand); color: #fff; }
.ahc-send:disabled { opacity: .5; }
.ahc-err { padding: 0 .8rem .5rem; font-size: .78rem; color: #b3261e; }
.ahc-err:empty { display: none; }

@media (max-width: 575.98px) {
  .ahc-panel { right: 0; bottom: 0; top: 0; width: 100vw; max-width: 100vw; height: auto; border-radius: 0; border: 0; }
  .ahc-open .ahc-fab, .ahc-open .ahc-tip { display: none; }
  html:has(body.ahc-open), body.ahc-open { overflow: hidden; }
}

/* ---------- 관리자 채팅 화면 ---------- */
/* 왼쪽 방 목록 + 오른쪽 대화. 방 정보·설정·보기 필터는 대화 위쪽 "정보·설정" 메뉴(.sc-panel)에 모은다. */
.sc {
  display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: 0;
  height: calc(100vh - 150px); min-height: 420px; background: #fff; border: 1px solid var(--line); border-radius: .5rem; overflow: hidden;
}
.sc-rooms { border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.sc-rooms-head { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; justify-content: space-between; padding: .6rem; border-bottom: 1px solid var(--line); }
.sc-room-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.sc-room-list li { border-bottom: 1px solid var(--line); }
.sc-room-list button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: .55rem .7rem; font-size: .85rem; color: var(--ink); }
.sc-room-list button:hover { background: var(--paper-soft); }
.sc-room-list button.active { background: #fbefe6; }
.sc-room-top { display: flex; align-items: center; gap: .35rem; }
.sc-room-name { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sc-room-time { font-size: .72rem; color: var(--ink-soft); }
.sc-room-last { display: block; color: var(--ink-soft); font-size: .78rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sc-tag { font-size: .66rem; padding: .05rem .35rem; border-radius: 4px; background: var(--paper-soft); color: var(--ink-soft); border: 1px solid var(--line); white-space: nowrap; }
.sc-tag.guest { background: #e8f1fb; color: #0b5394; border-color: #c6dcf3; }
.sc-tag.sc-suspect { background: #fff4e5; color: #9a5b00; border-color: #f3d19e; }
.sc-suspect-row { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem; padding: .35rem 0; border-bottom: 1px solid var(--line); }
.sc-suspect-row > div { flex: 1 1 100%; }
.sc-unread { min-width: 1.3rem; text-align: center; font-size: .7rem; font-weight: 600; border-radius: 999px; background: #d93025; color: #fff; padding: .05rem .35rem; }
.sc-room-list li { display: flex; align-items: stretch; }
.sc-room-list li.sc-empty { display: block; }
.sc-room-list li > button { flex: 1; min-width: 0; }
.sc-room-check { flex: none; display: flex; align-items: center; padding: 0 .1rem 0 .6rem; cursor: pointer; }
.sc-room-check input { width: 1.05rem; height: 1.05rem; margin: 0; cursor: pointer; }
.sc-room-list li.checked { background: #fff7ef; }
.sc-select-bar { display: flex; align-items: center; gap: .5rem; padding: .4rem .6rem; background: #fff4e5; border-bottom: 1px solid #f3d19e; font-size: .85rem; }
.sc-select-bar #sc-select-count { flex: 1; }
.sc-archive-note { padding: .4rem .6rem; font-size: .76rem; color: var(--ink-soft); background: var(--paper-soft); border-bottom: 1px solid var(--line); }
#sc-archive-view.active { background: var(--ink); border-color: var(--ink); color: #fff; }
.sc-panel-actions { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .9rem; padding-top: .7rem; border-top: 1px solid var(--line); }
.sc-empty { padding: 1rem; color: var(--ink-soft); font-size: .85rem; }


.sc-main { display: flex; flex-direction: column; min-width: 0; min-height: 0; position: relative; }
.sc-main-head { display: flex; align-items: center; gap: .5rem; padding: .45rem .7rem; border-bottom: 1px solid var(--line); }
.sc-back { display: none; padding: 0; flex: none; }
.sc-title-box { flex: 1; min-width: 0; }
.sc-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sc-sub { font-size: .74rem; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sc-sub:empty { display: none; }
.sc-sub .sc-ended { color: #b3261e; }
.sc-info-btn { flex: none; position: relative; }
.sc-info-btn.active .sc-info-caret { transform: rotate(180deg); }
.sc-info-dot { position: absolute; top: -4px; right: -4px; width: 10px; height: 10px; border-radius: 50%; background: #e8710a; border: 2px solid #fff; }

/* 정보·설정 메뉴 */
.sc-panel {
  position: absolute; left: 0; right: 0; top: var(--sc-head-h, 3.2rem); z-index: 5; max-height: calc(100% - var(--sc-head-h, 3.2rem));
  overflow-y: auto; background: #fff; border-bottom: 1px solid var(--line); box-shadow: 0 8px 18px rgba(0, 0, 0, .12);
  padding: .7rem .9rem .9rem; font-size: .84rem;
}
.sc-panel[hidden] { display: none; }
.sc-panel h2 { font-size: .8rem; font-weight: 600; color: var(--ink-soft); text-transform: none; margin: .8rem 0 .35rem; }
.sc-panel h2:first-child { margin-top: 0; }
.sc-filters { display: flex; gap: .5rem 1rem; flex-wrap: wrap; }
.sc-filter { display: flex; align-items: center; gap: .35rem; font-size: .8rem; }
.sc-filter select { width: auto; font-size: .8rem; padding-top: .1rem; padding-bottom: .1rem; }
.sc-panel dl { display: grid; grid-template-columns: 6.5rem minmax(0, 1fr); gap: .35rem .6rem; align-items: center; margin: 0; }
.sc-panel dt { font-weight: 400; color: var(--ink-soft); }
.sc-panel dd { margin: 0; word-break: break-all; }
.sc-panel dd select { max-width: 22rem; }
.sc-panel table { width: 100%; font-size: .78rem; }
.sc-panel th, .sc-panel td { padding: .15rem .2rem; border-bottom: 1px solid var(--line); }

.sc-messages { flex: 1; overflow-y: auto; padding: .8rem; background: var(--paper-soft); display: flex; flex-direction: column; gap: .5rem; }
.sc-msg { max-width: 78%; padding: .45rem .7rem; border-radius: 10px; background: #fff; border: 1px solid var(--line); font-size: .9rem; }
.sc-msg.from-staff, .sc-msg.from-ai { align-self: flex-end; background: #fbefe6; border-color: #f0d6c3; }
.sc-msg.from-ai { background: #eef4ec; border-color: #cfe2c9; }
.sc-msg.from-system { align-self: center; max-width: 95%; background: transparent; border: 1px dashed var(--line); color: var(--ink-soft); font-size: .78rem; }
.sc-msg.is-draft { border-style: dashed; }
.sc-meta { display: flex; gap: .4rem; font-size: .7rem; color: var(--ink-soft); margin-bottom: .15rem; }
.sc-line { white-space: pre-wrap; word-break: break-word; }
.sc-line + .sc-line { margin-top: .3rem; padding-top: .3rem; border-top: 1px dashed var(--line); }
.sc-lang { font-size: .62rem; text-transform: uppercase; color: var(--ink-soft); margin-right: .3rem; border: 1px solid var(--line); border-radius: 3px; padding: 0 .2rem; }
.sc-state { font-size: .7rem; color: #b07800; }
.sc-state.failed { color: #b3261e; }

/* 입력: 글칸 + 보내기, 그 아래 "번역 안 함"·"번역 미리보기" */
.sc-compose { padding: .5rem .7rem .5rem; border-top: 1px solid var(--line); }
.sc-compose-row { display: flex; gap: .5rem; align-items: flex-end; }
.sc-compose-row textarea { flex: 1; resize: vertical; font-size: .9rem; }
.sc-send { flex: none; }
.sc-opts { display: flex; align-items: center; gap: .6rem; margin-top: .35rem; font-size: .82rem; }
.sc-opts #sc-preview-btn { margin-left: auto; padding: .1rem .55rem; font-size: .8rem; }
.sc-preview { margin-bottom: .4rem; }

@media (max-width: 1199.98px) {
  .sc { grid-template-columns: 240px minmax(0, 1fr); }
}
@media (max-width: 767.98px) {
  .sc { grid-template-columns: minmax(0, 1fr); height: calc(100vh - 140px); }
  .sc-main { display: none; }
  .sc.sc-show-main .sc-rooms { display: none; }
  .sc.sc-show-main .sc-main { display: flex; }
  .sc-back { display: inline-block; }
  /* 휴대폰: 체크박스·보관함은 쓰지 않는다 (보관은 정보·설정 메뉴에서 한 방씩), 알림 단추는 종 모양만 */
  .sc-room-check, .sc-select-bar, #sc-archive-view, .sc-archive-note, .sc-notify-label { display: none !important; }

  /* 방을 열면 대화창이 화면 전체 (아이폰처럼 키보드가 화면을 덮기만 하면 admin-chat.js 가 높이를 맞춘다) */
  .sc.sc-show-main { position: fixed; left: 0; right: 0; top: 0; bottom: 0; height: auto; min-height: 0; z-index: 1050; border: 0; border-radius: 0; display: flex; flex-direction: column; }
  .sc.sc-show-main .sc-main { flex: 1; min-height: 0; }
  html.sc-lock, html.sc-lock body { overflow: hidden; }
  .sc-main-head { padding: .35rem .5rem; gap: .35rem; }
  .sc-title { font-size: .95rem; }
  .sc-info-label { display: none; }
  .sc-panel { bottom: 0; max-height: none; }
  .sc-messages { padding: .5rem; }
  .sc-msg { max-width: 88%; }
  /* 입력칸: 쓰지 않을 때는 한 줄 + 보내기 단추만 */
  .sc-compose { padding: .35rem .5rem calc(.35rem + env(safe-area-inset-bottom)); }
  .sc-compose-row textarea { resize: none; min-height: 2.5rem; max-height: 40dvh; }
  .sc-send-label { display: none; }
  .sc-compose:not(.sc-composing) .sc-opts { display: none; }
  .sc-compose-row textarea::placeholder { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
}

/* 휴대폰: 글자가 16px 보다 작은 입력칸을 누르면 아이폰이 화면을 확대하고 돌아오지 않는다 */
@media (max-width: 767.98px) {
  .sc textarea, .sc select, .sc input, .ahc-form textarea, .ahc-lang, .admin input, .admin select, .admin textarea { font-size: 16px !important; }
}

/* AI 초안 (직원 화면) */
.sc-tag.sc-draft { background: #eef4ec; color: #2e6b2a; border-color: #cfe2c9; }
.sc-ai-info { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem; font-size: .72rem; color: var(--ink-soft); margin-bottom: .25rem; }
.sc-ai-actions { display: flex; flex-wrap: wrap; gap: .3rem; margin-top: .4rem; }
.sc-ai-used { font-size: .68rem; color: var(--ink-soft); margin-top: .3rem; }
