/* 소상공인 채팅방 (html/chat.php) — 새 창 단독 화면.
 * 2026-11-03: 사이드바·대화 칸은 눈이 덜 피로한 어두운 녹회색(사용자 요청). 머리는 사이트와 같은 남색, 강조는 주황.
 */
:root {
  --navy: #1E2A4A;
  --orange: #F07A2B;
  --orange-dark: #D9651A;
  --orange-soft: #F5A46B;           /* 어두운 바탕 위 주황 글씨 */
  --red: #E57373;

  --bg: #2C3531;                    /* 대화 칸 */
  --side: #232B28;                  /* 사이드바·입력 칸 */
  --raise: #3A4440;                 /* 남의 말풍선·버튼 */
  --raise-line: #48534E;
  --hover: #303A36;
  --text: #E3E9E5;
  --text-sub: #B4C0BA;
  --muted: #8C9993;
  --line: #3A4440;

  --font: "Pretendard", "Noto Sans KR", -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  color-scheme: dark;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body { height: 100dvh; }   /* 휴대폰: 주소창·키보드가 나와도 화면 높이에 맞춤 */
body { display: flex; flex-direction: column; font-family: var(--font); color: var(--text); background: var(--bg); font-size: 15px; }
a { color: inherit; }

.chat-head { display: flex; align-items: center; gap: 12px; padding: 0 16px; height: 56px; background: var(--navy); color: #fff; flex: none; }
.chat-logo { font-weight: 800; font-size: 20px; text-decoration: none; background: linear-gradient(90deg, #F07A2B, #FFC83D); -webkit-background-clip: text; background-clip: text; color: transparent; }
.chat-head h1 { font-size: 17px; font-weight: 700; }
.chat-head-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.chat-me { font-size: 13px; opacity: .8; }
.chat-exit { padding: 5px 14px; border-radius: 999px; background: rgba(255, 255, 255, .12); border: 1px solid rgba(255, 255, 255, .3); color: #fff; font-size: 13px; font-weight: 600; text-decoration: none; white-space: nowrap; }
.chat-exit:hover { background: var(--orange); border-color: var(--orange); }
.chat-side-btn { display: none; padding: 4px 10px; border: 1px solid rgba(255, 255, 255, .35); border-radius: 999px; background: none; color: #fff; font: inherit; font-size: 13px; cursor: pointer; }

/* 접속자 사이드바 + 대화 칸 */
.chat-wrap { flex: 1; min-height: 0; display: flex; }
.chat-side { flex: none; width: 250px; overflow-y: auto; background: var(--side); border-right: 1px solid var(--line); padding: 14px 12px; display: flex; flex-direction: column; }
.chat-side h2 { font-size: 15px; font-weight: 700; color: var(--text-sub); margin: 0 4px 10px; }
.chat-side h2 b { color: var(--orange-soft); }
.chat-users { flex: none; list-style: none; display: flex; flex-direction: column; gap: 2px; }
.chat-users li { display: flex; align-items: center; gap: 10px; padding: 6px 6px; border-radius: 6px; font-size: 17px; letter-spacing: 0.02em; min-width: 0; }
.chat-users li:hover { background: var(--hover); }
.chat-users .chat-av { width: 32px; height: 32px; font-size: 13px; position: relative; overflow: visible; }
.chat-users .chat-av img { border-radius: 50%; }
.chat-users .chat-av::after { content: ""; position: absolute; right: -1px; bottom: -1px; width: 9px; height: 9px; border-radius: 50%; background: #3DCB6E; border: 2px solid var(--side); }
.chat-users .chat-uname { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-users a { text-decoration: none; }
.chat-users a:hover { color: var(--orange-soft); text-decoration: underline; }
.chat-users .chat-you { flex: none; font-size: 13px; color: var(--muted); }
.chat-guests { margin: 8px 6px 0; font-size: 15px; color: var(--muted); }

/* 사이드바 맨 아래 @ 안내 */
.chat-ai-guide { flex: none; margin-top: auto; padding: 12px; word-break: keep-all; border-radius: 10px; background: #2E3833; border: 1px solid #3F4A44; font-size: 13px; line-height: 1.55; color: #fff; }
.chat-ai-guide p + p { margin-top: 4px; }
.chat-ai-guide b { color: var(--orange-soft); }
.chat-ai-guide .sub { color: #fff; }

.chat-room { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; }

.chat-body { flex: 1; overflow-y: auto; padding: 12px 16px 16px; background: var(--bg); }
.chat-notice { margin: 4px auto 16px; max-width: 720px; text-align: center; font-size: 17px; letter-spacing: 0.04em; word-break: keep-all; color: #fff; line-height: 1.6; }
.chat-notice b { color: var(--orange-soft); }
.chat-more { display: block; margin: 0 auto 8px; padding: 6px 14px; border: 1px solid var(--raise-line); border-radius: 999px; background: var(--raise); font: inherit; font-size: 13px; color: var(--text-sub); cursor: pointer; }
.chat-more:hover { border-color: var(--orange); color: var(--orange-soft); }
.chat-empty { text-align: center; color: var(--muted); margin-top: 40px; }

.chat-list { list-style: none; display: flex; flex-direction: column; gap: 2px; }
.chat-day { align-self: center; margin: 12px 0 6px; padding: 3px 12px; border-radius: 999px; background: #252D2A; font-size: 12px; color: var(--muted); }
/* 옛날 채팅처럼 한 줄씩: 닉네임 : 메시지 (모두 왼쪽 정렬), 시간은 오른쪽 끝에 흐리게 */
.chat-msg { display: flex; align-items: baseline; gap: 10px; padding: 4px 8px; border-radius: 6px; font-size: 17px; line-height: 1.6; letter-spacing: 0.04em; }
.chat-msg:hover { background: rgba(255, 255, 255, .04); }
.chat-line { flex: 1; min-width: 0; word-break: break-word; overflow-wrap: anywhere; }
.chat-name { font-weight: 700; color: #9CC8B0; white-space: nowrap; }
.chat-name a { text-decoration: none; }
.chat-name a:hover { text-decoration: underline; }
.chat-sep { color: #fff; }
.chat-msg.mine .chat-name { color: var(--orange-soft); }
.chat-bubble { color: #fff; white-space: pre-wrap; }
.chat-bubble a { color: #8CC4FF; }
.chat-badge { margin-left: 4px; padding: 0 5px; border-radius: 4px; background: var(--navy); color: #fff; font-size: 10px; vertical-align: 1px; }
.chat-av { flex: none; width: 34px; height: 34px; border-radius: 50%; background: #56635D; color: #fff; font-weight: 700; font-size: 14px; display: grid; place-items: center; overflow: hidden; }
.chat-av img { width: 100%; height: 100%; object-fit: cover; }
.chat-meta { flex: none; font-size: 12px; color: var(--muted); display: flex; align-items: baseline; gap: 6px; }
.chat-del { border: 0; background: none; padding: 0; font: inherit; font-size: 11px; color: var(--muted); cursor: pointer; visibility: hidden; }
.chat-msg:hover .chat-del, .chat-del:focus { visibility: visible; }
.chat-del:hover { color: var(--red); text-decoration: underline; }

.chat-new { position: absolute; left: 50%; bottom: 84px; transform: translateX(-50%); padding: 7px 16px; border: 0; border-radius: 999px; background: var(--orange); color: #fff; font: inherit; font-size: 13px; box-shadow: 0 4px 12px rgba(0, 0, 0, .35); cursor: pointer; }

.chat-foot { flex: none; padding: 12px 16px; background: var(--side); border-top: 1px solid var(--line); }
.chat-foot form { display: flex; gap: 8px; }
.chat-foot input { flex: 1; min-width: 0; height: 44px; padding: 0 14px; border: 1px solid var(--raise-line); border-radius: 22px; background: var(--bg); color: var(--text); font: inherit; outline: none; }
.chat-foot input::placeholder { color: var(--muted); }
.chat-foot input:focus { border-color: var(--orange); }
.chat-foot button { flex: none; height: 44px; padding: 0 20px; border: 0; border-radius: 22px; background: var(--orange); color: #fff; font: inherit; font-weight: 700; cursor: pointer; }
.chat-foot button:hover { background: var(--orange-dark); }
.chat-foot button:disabled { opacity: .6; cursor: default; }
.chat-err { margin-top: 6px; font-size: 13px; color: var(--red); }
.chat-login { text-align: center; padding: 8px 0; color: var(--text-sub); }
.chat-login a { color: var(--orange-soft); font-weight: 700; }

/* 창이 좁으면 사이드바를 접고 머리의 '접속 N' 버튼으로 위에 겹쳐 열기 */
@media (max-width: 640px) {
  .chat-side-btn { display: inline-block; }
  .chat-side { display: none; position: absolute; top: 56px; left: 0; bottom: 0; z-index: 5; width: min(270px, 82vw); box-shadow: 4px 0 16px rgba(0, 0, 0, .4); }
  body.side-open .chat-side { display: flex; }
  .chat-me { display: none; }
}

/* 휴대폰 (2026-11-03) */
@media (max-width: 480px) {
  .chat-head { gap: 8px; padding: 0 10px; height: 52px; }
  .chat-side { top: 52px; }
  .chat-logo { font-size: 18px; }
  .chat-head h1 { font-size: 15px; white-space: nowrap; }
  .chat-head-right { gap: 6px; }
  .chat-side-btn, .chat-exit { padding: 4px 9px; font-size: 12px; }
  .chat-body { padding: 10px 8px 12px; }
  .chat-notice { font-size: 15px; }
  .chat-msg { font-size: 16px; padding: 4px 4px; gap: 6px; }
  .chat-event { font-size: 15px; }
  .chat-img { max-width: min(240px, 100%); }
  .chat-foot { padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); }
  .chat-foot form { gap: 6px; }
  .chat-foot form .chat-plus { width: 40px; height: 40px; font-size: 24px; }
  .chat-foot form .chat-nick { width: 72px; padding: 0 6px; font-size: 15px; }
  .chat-foot form input { height: 40px; padding: 0 12px; }
  .chat-foot form .chat-send { height: 40px; padding: 0 14px; }
  .chat-new { bottom: 70px; }
}
/* 아이폰은 입력칸 글씨가 16px 보다 작으면 누를 때 화면을 확대함 */
@media (max-width: 1024px) { .chat-foot input { font-size: 16px; } }
/* 손가락 화면(마우스 올리기 없음): 지우기 버튼 늘 보이게 */
@media (hover: none) { .chat-del { visibility: visible; } }

/* 나사장AI — 이름 앞 @, 사이드바 이름을 누르면 입력창에 @ */
.chat-users li.ai .chat-av { background: linear-gradient(135deg, #F07A2B, #FFC83D); font-size: 12px; }
.chat-msg.ai .chat-name { color: #F2C66D; }
.chat-msg.ai .chat-bubble { color: #fff; }
.chat-users li.ai .chat-uname { font-weight: 700; }
.chat-ask { border: 0; background: none; padding: 0; font: inherit; font-weight: 700; color: var(--orange-soft); cursor: pointer; }
.chat-ask:hover { text-decoration: underline; }

/* 비회원(손님): 입력창 왼쪽 닉네임 칸, 이름 색은 연회색 */
.chat-foot .chat-nick { flex: none; width: 120px; padding: 0 12px; text-align: center; font-weight: 700; color: #DDE5E0; }
.chat-msg.guest:not(.mine) .chat-name { color: #C7D0CB; font-weight: 600; }
.chat-users li.guest .chat-av { background: #4A5550; }
.chat-users li.guest .chat-uname { color: #C7D0CB; }
.chat-foot .chat-login { padding: 8px 0 0; font-size: 13px; color: var(--muted); }

/* 사진: 입력창 왼쪽 + 버튼, 채팅 속 사진(누르면 원본 새 창) */
.chat-foot .chat-plus { flex: none; width: 44px; height: 44px; padding: 0; border-radius: 50%; background: var(--raise); border: 1px solid var(--raise-line); color: #fff; font-size: 26px; font-weight: 400; line-height: 1; }
.chat-foot .chat-plus:hover { background: var(--orange); border-color: var(--orange); }
.chat-foot .chat-plus.busy { animation: chatBusy 1s linear infinite; }
@keyframes chatBusy { to { transform: rotate(360deg); } }
.chat-img { display: inline-block; vertical-align: top; margin: 3px 0 2px; max-width: min(320px, 100%); }
.chat-img img { display: block; max-width: 100%; height: auto; max-height: 360px; width: auto; border-radius: 8px; border: 1px solid var(--raise-line); background: var(--raise); object-fit: contain; }

/* 입장·퇴장 알림 */
.chat-event { align-self: center; margin: 4px 0; font-size: 17px; color: #C9A27A; letter-spacing: 0.04em; }

/* 나사장AI 입력 중… (답을 다 만들면 사라지고 답이 한 번에 나옴) */
.chat-typing { margin-top: 4px; padding: 4px 8px; font-size: 17px; color: #fff; letter-spacing: 0.04em; }
.chat-typing b { color: #F2C66D; }
.chat-typing i { font-style: normal; animation: chatDot 1.2s infinite; }
.chat-typing i:nth-child(3) { animation-delay: .2s; }
.chat-typing i:nth-child(4) { animation-delay: .4s; }
@keyframes chatDot { 0%, 60%, 100% { opacity: .2; } 30% { opacity: 1; } }
@media (max-width: 480px) { .chat-typing { font-size: 16px; } }
