/* ============================================================
   GTALK(지톡) — 기본 레이아웃 & 컴포넌트
   색상은 전부 themes.css 변수에서 가져옴
   ============================================================ */

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

:root {
  --radius: 14px;
  --radius-sm: 9px;
  --font: "Pretendard", -apple-system, BlinkMacSystemFont, "Noto Sans KR",
    "Segoe UI", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
}

html, body { height: 100%; }

body {
  font-family: var(--font);
  background: var(--bg-base);
  color: var(--text);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, textarea { font-family: inherit; color: inherit; }
::selection { background: var(--accent); color: var(--accent-text); }

/* ---------- 배경 오브 ---------- */
.bg { position: fixed; inset: 0; z-index: 0; overflow: hidden; pointer-events: none; }
.bg .orb { position: absolute; border-radius: 50%; filter: blur(110px); opacity: 0.85; }
.bg .orb.o1 { width: 480px; height: 480px; left: -140px; top: -140px; background: var(--bg-1); animation: drift 22s ease-in-out infinite alternate; }
.bg .orb.o2 { width: 560px; height: 560px; right: -180px; bottom: -200px; background: var(--bg-2); animation: drift 26s ease-in-out infinite alternate-reverse; }
.bg .orb.o3 { width: 300px; height: 300px; left: 45%; top: 55%; background: var(--bg-1); opacity: 0.5; animation: drift 30s ease-in-out infinite alternate; }
@keyframes drift {
  from { transform: translate(0, 0) scale(1); }
  to { transform: translate(70px, -50px) scale(1.15); }
}

/* ============================================================
   로그인 오버레이
   ============================================================ */
#auth {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  padding: 20px; overflow-y: auto;
  background: color-mix(in srgb, var(--bg-base) 72%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  transition: opacity 0.35s ease, visibility 0.35s;
}
#auth.hidden { opacity: 0; visibility: hidden; pointer-events: none; }

.login-card {
  width: min(560px, 100%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 22px;
  box-shadow: var(--shadow);
  padding: 34px 30px 28px;
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  animation: pop 0.45s cubic-bezier(0.2, 1.2, 0.3, 1);
  max-height: calc(100vh - 40px);
  overflow-y: auto;
}
@keyframes pop {
  from { transform: translateY(26px) scale(0.97); opacity: 0; }
  to { transform: none; opacity: 1; }
}

.brand { display: flex; align-items: center; gap: 13px; margin-bottom: 6px; }
.brand .logo {
  width: 46px; height: 46px; border-radius: 14px; flex: none;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 8px 22px color-mix(in srgb, var(--accent) 45%, transparent);
}
.brand h1 { font-size: 22px; letter-spacing: -0.5px; }
.brand h1 span { background: linear-gradient(135deg, var(--accent), var(--accent-2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.login-sub { color: var(--muted); font-size: 13.5px; margin-bottom: 20px; }

.field label { display: block; font-size: 12.5px; font-weight: 600; color: var(--muted); margin: 16px 0 7px; letter-spacing: 0.2px; }
.field input {
  width: 100%; padding: 12px 14px; font-size: 15px;
  background: var(--input-bg); border: 1px solid var(--border);
  border-radius: var(--radius-sm); outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.field input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }

.room-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 9px; margin-top: 4px; }
.room-card {
  text-align: left; padding: 12px; border-radius: var(--radius-sm);
  background: var(--panel-2); border: 1px solid var(--border);
  transition: transform 0.15s, border-color 0.2s, background 0.2s;
}
.room-card:hover { transform: translateY(-2px); border-color: var(--accent); }
.room-card .rc-top { display: flex; align-items: center; gap: 7px; font-weight: 700; font-size: 14px; }
.room-card .rc-topic { font-size: 12px; color: var(--muted); margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.room-card .rc-online { font-size: 11.5px; color: var(--ok); margin-top: 6px; font-weight: 600; }
.room-card .rc-online::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--ok); margin-right: 5px; }

.create-row { display: flex; gap: 8px; margin-top: 8px; }
.create-row input {
  flex: 1; padding: 11px 13px; font-size: 14px;
  background: var(--input-bg); border: 1px solid var(--border);
  border-radius: var(--radius-sm); outline: none; min-width: 0;
}
.create-row input:focus { border-color: var(--accent); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 11px 18px; font-size: 14px; font-weight: 700;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: var(--accent-text);
  transition: transform 0.12s, filter 0.2s, box-shadow 0.2s;
  box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 35%, transparent);
  white-space: nowrap;
}
.btn:hover { filter: brightness(1.08); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }
.btn.ghost {
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); box-shadow: none;
}
.btn.ghost:hover { border-color: var(--accent); }
.btn.danger { background: var(--danger); color: #fff; box-shadow: 0 6px 18px color-mix(in srgb, var(--danger) 35%, transparent); }
.btn.small { padding: 8px 13px; font-size: 13px; }
.btn.block { width: 100%; margin-top: 20px; padding: 13px; font-size: 15px; border-radius: 12px; }

.login-err {
  display: none; margin-top: 14px; padding: 11px 13px; font-size: 13.5px;
  background: color-mix(in srgb, var(--danger) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--danger) 45%, transparent);
  color: var(--danger); border-radius: var(--radius-sm);
}
.login-err.show { display: block; animation: shake 0.3s; }
@keyframes shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }

.login-foot { margin-top: 16px; text-align: center; font-size: 12px; color: var(--muted); }

/* ============================================================
   앱 레이아웃
   ============================================================ */
#app {
  position: relative; z-index: 1;
  display: grid; grid-template-columns: 302px 1fr;
  height: 100dvh; max-width: 1280px; margin: 0 auto;
  padding: 16px; gap: 14px;
  visibility: hidden;
}
#app.ready { visibility: visible; }

/* ---------- 사이드바 ---------- */
#sidebar {
  display: flex; flex-direction: column; min-height: 0;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 18px; box-shadow: var(--shadow);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  overflow: hidden;
}
.side-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 16px 14px; }

.side-brand { display: flex; align-items: center; gap: 10px; padding: 2px 4px 14px; }
.side-brand .logo {
  width: 36px; height: 36px; border-radius: 11px; flex: none;
  display: flex; align-items: center; justify-content: center; font-size: 19px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}
.side-brand b { font-size: 16px; letter-spacing: -0.3px; }

.me-card {
  display: flex; align-items: center; gap: 11px;
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 11px 12px; margin-bottom: 16px;
}
.avatar {
  width: 40px; height: 40px; border-radius: 50%; flex: none;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 16px; color: #fff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}
.me-card .who { min-width: 0; flex: 1; }
.me-card .who b { display: block; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-card .who span { font-size: 12px; color: var(--ok); }
.admin-badge {
  font-size: 10.5px; font-weight: 800; padding: 3px 8px; border-radius: 20px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: var(--accent-text); letter-spacing: 0.4px; flex: none;
}

.side-sec { margin-bottom: 18px; }
.side-sec > h3 {
  font-size: 11.5px; font-weight: 800; letter-spacing: 1.2px;
  color: var(--muted); margin: 0 4px 9px;
  display: flex; align-items: center; justify-content: space-between;
}
.side-sec > h3 .cnt {
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 12px; padding: 1px 8px; font-size: 11px; letter-spacing: 0;
}

.theme-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; }
.theme-btn {
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  padding: 8px 2px 7px; border-radius: 10px;
  border: 1px solid transparent; transition: background 0.2s, border-color 0.2s;
}
.theme-btn:hover { background: var(--panel-2); }
.theme-btn.active { border-color: var(--accent); background: var(--panel-2); }
.theme-btn .swatch {
  width: 30px; height: 30px; border-radius: 50%;
  border: 2px solid color-mix(in srgb, var(--text) 18%, transparent);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.15);
}
.theme-btn small { font-size: 10px; color: var(--muted); font-weight: 600; line-height: 1.2; }
.theme-btn.active small { color: var(--text); }

.room-list { display: flex; flex-direction: column; gap: 6px; }
.room-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 9px 10px; border-radius: 11px; text-align: left;
  border: 1px solid transparent; transition: background 0.15s, border-color 0.2s;
}
.room-item:hover { background: var(--panel-2); }
.room-item.active { background: var(--panel-2); border-color: var(--accent); }
.room-item .r-emoji { font-size: 19px; flex: none; }
.room-item .r-meta { flex: 1; min-width: 0; }
.room-item .r-meta b { display: block; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.room-item .r-meta span { font-size: 11.5px; color: var(--muted); }
.room-item .r-online { font-size: 11px; font-weight: 700; color: var(--ok); flex: none; }
.unread {
  min-width: 21px; height: 21px; padding: 0 6px; border-radius: 12px; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 800;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: var(--accent-text);
}

.user-list { display: flex; flex-direction: column; gap: 2px; max-height: 190px; overflow-y: auto; }
.user-row { display: flex; align-items: center; gap: 9px; padding: 6px 8px; border-radius: 9px; font-size: 13px; }
.user-row:hover { background: var(--panel-2); }
.user-row .avatar { width: 28px; height: 28px; font-size: 12px; }
.user-row .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); margin-left: auto; flex: none; box-shadow: 0 0 8px var(--ok); }
.user-row .nm { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-row .mini-badge { font-size: 12px; }

.admin-box {
  background: color-mix(in srgb, var(--danger) 7%, transparent);
  border: 1px solid color-mix(in srgb, var(--danger) 30%, transparent);
  border-radius: var(--radius); padding: 12px; font-size: 13px;
}
.admin-box h4 { font-size: 12px; letter-spacing: 0.6px; color: var(--danger); margin-bottom: 8px; }
.admin-box h4:not(:first-child) { margin-top: 12px; }
.admin-box input {
  width: 100%; padding: 9px 11px; font-size: 13px; margin-bottom: 7px;
  background: var(--input-bg); border: 1px solid var(--border);
  border-radius: 8px; outline: none;
}
.admin-box input:focus { border-color: var(--danger); }
.ban-list { display: flex; flex-direction: column; gap: 5px; margin-top: 4px; }
.ban-row {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  font-size: 12.5px; padding: 6px 9px; border-radius: 8px; background: var(--panel-2);
}
.ban-row button { color: var(--ok); font-weight: 700; font-size: 12px; }
.ban-empty { font-size: 12px; color: var(--muted); }

.side-foot { padding: 12px 14px; border-top: 1px solid var(--border); display: flex; gap: 8px; }
.side-foot .btn { flex: 1; }

/* ---------- 채팅 메인 ---------- */
#chat {
  display: flex; flex-direction: column; min-height: 0; min-width: 0;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 18px; box-shadow: var(--shadow);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  overflow: hidden;
}

.chat-head {
  display: flex; align-items: center; gap: 12px;
  padding: 13px 18px; border-bottom: 1px solid var(--border); flex: none;
}
#menuBtn { display: none; font-size: 20px; padding: 6px 9px; border-radius: 9px; }
#menuBtn:hover { background: var(--panel-2); }
.chat-head .r-emoji { font-size: 26px; }
.chat-head .r-info { flex: 1; min-width: 0; }
.chat-head .r-info b { font-size: 16px; letter-spacing: -0.3px; display: flex; align-items: center; gap: 7px; }
.chat-head .r-info span { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.online-pill {
  flex: none; font-size: 12.5px; font-weight: 700; color: var(--ok);
  background: color-mix(in srgb, var(--ok) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--ok) 30%, transparent);
  padding: 6px 12px; border-radius: 20px;
}

#messages { flex: 1; overflow-y: auto; padding: 20px 22px 10px; scroll-behavior: smooth; }

.day-line { display: flex; align-items: center; gap: 12px; margin: 16px 0 12px; color: var(--muted); font-size: 12px; font-weight: 600; }
.day-line::before, .day-line::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.day-line span { background: var(--panel-2); border: 1px solid var(--border); padding: 4px 14px; border-radius: 14px; }

.msg { display: flex; gap: 10px; margin-bottom: 4px; animation: msgIn 0.25s ease; }
@keyframes msgIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.msg .avatar { width: 36px; height: 36px; font-size: 14px; margin-top: 2px; }
.msg .body { min-width: 0; max-width: min(72%, 560px); }
.msg .meta { display: flex; align-items: baseline; gap: 7px; margin-bottom: 3px; }
.msg .meta b { font-size: 13px; }
.msg .meta time { font-size: 11px; color: var(--muted); }
.msg .meta .edited { font-size: 10.5px; color: var(--muted); }
.msg .bubble {
  display: inline-block; padding: 10px 14px; font-size: 14.5px; line-height: 1.55;
  background: var(--bubble-in); color: var(--bubble-in-text);
  border-radius: 4px 16px 16px 16px; border: 1px solid var(--border);
  word-break: break-word; overflow-wrap: anywhere;
}
.msg .bubble a { color: var(--accent); }
.msg.mine { flex-direction: row-reverse; }
.msg.mine .body { display: flex; flex-direction: column; align-items: flex-end; }
.msg.mine .meta { flex-direction: row-reverse; }
.msg.mine .bubble {
  background: var(--bubble-out); color: var(--bubble-out-text);
  border: none; border-radius: 16px 4px 16px 16px;
}
.msg.mine .bubble a { color: inherit; text-decoration: underline; }
.bubble p + p { margin-top: 6px; }

/* 연속 메시지 묶음 (compact) */
.msg.compact { margin-top: -1px; }
.msg.compact .avatar { visibility: hidden; height: 0; margin-top: 0; }
.msg.compact .msg-actions { margin-top: 1px; }

.msg-img { display: block; max-width: 280px; max-height: 220px; border-radius: 10px; cursor: zoom-in; margin-bottom: 6px; }
.msg-img:last-child { margin-bottom: 0; }
.file-chip {
  display: inline-flex; align-items: center; gap: 10px;
  padding: 9px 13px 9px 9px; border-radius: 11px; margin-bottom: 6px;
  background: color-mix(in srgb, currentColor 8%, transparent);
  border: 1px dashed color-mix(in srgb, currentColor 35%, transparent);
  font-size: 13px; text-decoration: none; color: inherit; max-width: 100%;
}
.file-chip:last-child { margin-bottom: 0; }
.file-chip .fi { font-size: 22px; }
.file-chip .fn { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 200px; }
.file-chip .fs { font-size: 11.5px; opacity: 0.75; }

.reactions { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 5px; }
.react-chip {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12.5px; padding: 3px 9px; border-radius: 14px;
  background: var(--chip); border: 1px solid var(--border);
  transition: transform 0.1s, border-color 0.2s;
}
.react-chip:hover { transform: scale(1.07); }
.react-chip.me { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.react-chip b { font-size: 11.5px; }

.msg-actions {
  display: flex; gap: 2px; margin-top: 3px; opacity: 0; transition: opacity 0.15s;
}
.msg:hover .msg-actions, .msg-actions.open { opacity: 1; }
.msg.mine .msg-actions { justify-content: flex-end; }
.act-btn {
  font-size: 13px; padding: 4px 8px; border-radius: 8px; color: var(--muted);
  position: relative;
}
.act-btn:hover { background: var(--panel-2); color: var(--text); }
.act-btn.warn:hover { color: var(--danger); }

.react-palette {
  position: absolute; bottom: calc(100% + 6px); z-index: 20;
  display: none; gap: 2px; padding: 7px 9px; border-radius: 13px;
  background: var(--panel); border: 1px solid var(--border); box-shadow: var(--shadow);
}
.msg .react-palette { left: 0; }
.msg.mine .react-palette { right: 0; left: auto; }
.react-palette.open { display: flex; animation: pop 0.18s ease; }
.react-palette button { font-size: 19px; padding: 4px 5px; border-radius: 8px; transition: transform 0.1s; }
.react-palette button:hover { transform: scale(1.3); }

.sys { display: flex; justify-content: center; margin: 10px 0; animation: msgIn 0.25s ease; }
.sys span {
  font-size: 12.5px; color: var(--muted); text-align: center;
  background: var(--panel-2); border: 1px solid var(--border);
  padding: 6px 16px; border-radius: 16px; max-width: 90%;
}
.sys.warn span { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.sys.ok span { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, transparent); }

#typingBar { min-height: 26px; padding: 4px 24px 0; font-size: 12.5px; color: var(--muted); flex: none; }
#typingBar .dots i {
  display: inline-block; width: 5px; height: 5px; border-radius: 50%;
  background: var(--muted); margin-left: 2px; animation: blink 1.2s infinite;
}
#typingBar .dots i:nth-child(2) { animation-delay: 0.2s; }
#typingBar .dots i:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 60%, 100% { opacity: 0.25; } 30% { opacity: 1; } }

/* ---------- 입력창 ---------- */
#composer { padding: 10px 18px 16px; flex: none; position: relative; }
#editBanner {
  display: none; align-items: center; gap: 8px; font-size: 12.5px;
  color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  padding: 7px 12px; border-radius: 10px; margin-bottom: 8px;
}
#editBanner.show { display: flex; }
#editBanner button { margin-left: auto; font-size: 14px; color: var(--muted); }
#uploadBar { display: none; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); margin-bottom: 8px; }
#uploadBar.show { display: flex; }
#uploadBar .bar { flex: 1; height: 6px; border-radius: 4px; background: var(--panel-2); overflow: hidden; }
#uploadBar .bar i { display: block; height: 100%; width: 40%; border-radius: 4px; background: linear-gradient(90deg, var(--accent), var(--accent-2)); animation: slide 1s infinite linear; }
@keyframes slide { from { margin-left: -40%; } to { margin-left: 100%; } }

.input-row { display: flex; align-items: flex-end; gap: 9px; }
.icon-btn {
  width: 42px; height: 42px; flex: none; border-radius: 12px; font-size: 19px;
  background: var(--panel-2); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  transition: border-color 0.2s, transform 0.12s;
}
.icon-btn:hover { border-color: var(--accent); transform: translateY(-1px); }
#msgInput {
  flex: 1; resize: none; font-size: 14.5px; line-height: 1.5;
  background: var(--input-bg); border: 1px solid var(--border);
  border-radius: 13px; padding: 11px 15px; outline: none;
  max-height: 130px; min-height: 44px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
#msgInput:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }
#sendBtn { width: 46px; height: 44px; font-size: 18px; border-radius: 13px; padding: 0; }
.hint { margin-top: 7px; font-size: 11.5px; color: var(--muted); text-align: center; }
.hint kbd {
  font-family: inherit; font-size: 10.5px; padding: 1px 6px; border-radius: 5px;
  background: var(--panel-2); border: 1px solid var(--border);
}

#emojiPanel {
  position: absolute; bottom: calc(100% - 6px); left: 18px; z-index: 30;
  display: none; grid-template-columns: repeat(8, 1fr); gap: 2px;
  padding: 10px; border-radius: 14px;
  background: var(--panel); border: 1px solid var(--border); box-shadow: var(--shadow);
}
#emojiPanel.open { display: grid; animation: pop 0.18s ease; }
#emojiPanel button { font-size: 21px; padding: 5px; border-radius: 9px; }
#emojiPanel button:hover { background: var(--panel-2); transform: scale(1.15); }

#newMsgBtn {
  position: absolute; left: 50%; bottom: calc(100% + 10px); transform: translateX(-50%);
  display: none; align-items: center; gap: 6px; z-index: 10;
  font-size: 12.5px; font-weight: 700; padding: 8px 16px; border-radius: 20px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: var(--accent-text); box-shadow: var(--shadow); white-space: nowrap;
}
#newMsgBtn.show { display: inline-flex; animation: pop 0.2s ease; }

/* ============================================================
   라이트박스 / 토스트
   ============================================================ */
#lightbox {
  position: fixed; inset: 0; z-index: 100; display: none;
  align-items: center; justify-content: center; padding: 30px;
  background: rgba(0, 0, 0, 0.85); backdrop-filter: blur(6px);
}
#lightbox.open { display: flex; }
#lightbox img { max-width: 100%; max-height: 100%; border-radius: 12px; box-shadow: 0 30px 90px rgba(0, 0, 0, 0.6); }
#lightbox .x { position: absolute; top: 18px; right: 22px; font-size: 30px; color: #fff; opacity: 0.8; }
#lightbox .x:hover { opacity: 1; }

#toasts { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 120; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast {
  font-size: 13.5px; font-weight: 600; padding: 11px 20px; border-radius: 13px;
  background: var(--panel); color: var(--text);
  border: 1px solid var(--border); box-shadow: var(--shadow);
  animation: toastIn 0.3s cubic-bezier(0.2, 1.2, 0.3, 1);
  max-width: min(90vw, 440px); text-align: center;
}
.toast.err { border-color: color-mix(in srgb, var(--danger) 55%, transparent); color: var(--danger); }
.toast.ok { border-color: color-mix(in srgb, var(--ok) 55%, transparent); color: var(--ok); }
@keyframes toastIn { from { opacity: 0; transform: translateY(14px) scale(0.96); } to { opacity: 1; transform: none; } }
.toast.out { opacity: 0; transform: translateY(8px); transition: all 0.3s; }

/* ---------- 스크롤바 ---------- */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: color-mix(in srgb, var(--muted) 45%, transparent); border-radius: 6px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: color-mix(in srgb, var(--muted) 70%, transparent); background-clip: content-box; border: 2px solid transparent; }

/* ============================================================
   반응형
   ============================================================ */
#sideBackdrop { display: none; }

@media (max-width: 920px) {
  #app { grid-template-columns: 1fr; padding: 10px; gap: 0; }
  #sidebar {
    position: fixed; top: 10px; bottom: 10px; left: 10px; width: min(320px, 86vw); z-index: 60;
    transform: translateX(calc(-100% - 20px)); transition: transform 0.3s cubic-bezier(0.2, 0.9, 0.3, 1);
  }
  #sidebar.open { transform: none; }
  #menuBtn { display: block; }
  #sideBackdrop.show {
    display: block; position: fixed; inset: 0; z-index: 55;
    background: rgba(0, 0, 0, 0.45); backdrop-filter: blur(2px);
  }
  #messages { padding: 14px 14px 6px; }
  .msg .body { max-width: 82%; }
  .chat-head { padding: 11px 13px; }
  #composer { padding: 8px 12px 12px; }
  .hint { display: none; }
  .login-card { padding: 26px 20px 22px; }
  #thread {
    position: fixed; top: 10px; bottom: 10px; right: 10px; width: min(340px, 90vw); z-index: 60;
  }
}

/* ============================================================
   GTALK v2 — 인증탭 / 서버 / 답장 / 스레드 / DM
   ============================================================ */

.auth-tabs { display: flex; gap: 8px; margin: 4px 0 6px; }
.auth-tab {
  flex: 1; padding: 11px; font-size: 14px; font-weight: 700;
  border-radius: 11px; color: var(--muted);
  background: var(--panel-2); border: 1px solid var(--border);
  transition: all 0.2s;
}
.auth-tab.active {
  color: var(--accent-text);
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-color: transparent;
  box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 35%, transparent);
}
#auth .field input { margin-bottom: 2px; }
#auth form.hidden-form { display: none; }

.cur-server {
  font-size: 12.5px; font-weight: 700; color: var(--accent);
  padding: 7px 10px; margin-bottom: 7px; border-radius: 9px;
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.link-btn {
  font-size: 12.5px; color: var(--muted); margin-top: 8px; padding: 4px 6px;
}
.link-btn:hover { color: var(--danger); }

.server-item .r-meta b { display: flex; align-items: center; gap: 6px; }
.owner-crown { font-size: 12px; }
.joined-tag {
  font-size: 10px; font-weight: 800; padding: 2px 7px; border-radius: 10px; flex: none;
  background: color-mix(in srgb, var(--ok) 14%, transparent); color: var(--ok);
}

.admin-box select {
  width: 100%; padding: 9px 11px; font-size: 13px; margin-bottom: 7px;
  background: var(--input-bg); border: 1px solid var(--border); color: inherit;
  border-radius: 8px; outline: none;
}

.user-row .dm-btn {
  font-size: 12px; font-weight: 700; padding: 4px 9px; border-radius: 8px; flex: none;
  background: var(--panel-2); border: 1px solid var(--border); color: var(--muted);
}
.user-row .dm-btn:hover { color: var(--text); border-color: var(--accent); }
.user-row.offline { opacity: 0.55; }
.user-row.offline .dot { background: var(--muted); box-shadow: none; }

/* 답장 인용 블록 */
.reply-quote {
  display: block; font-size: 12.5px; line-height: 1.45; text-align: left;
  padding: 7px 11px; margin-bottom: 7px; border-radius: 9px; max-width: 100%;
  background: color-mix(in srgb, currentColor 9%, transparent);
  border-left: 3px solid var(--accent); opacity: 0.92; cursor: pointer;
}
.reply-quote b { display: block; font-size: 11.5px; color: var(--accent); margin-bottom: 1px; }
.msg.mine .reply-quote b { color: inherit; opacity: 0.85; }
.reply-quote span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.reply-count {
  font-size: 11.5px; font-weight: 700; color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  padding: 3px 10px; border-radius: 12px; margin-top: 5px;
}
.reply-count:hover { filter: brightness(1.1); }

#replyBanner {
  display: none; align-items: center; gap: 8px; font-size: 12.5px;
  color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  padding: 7px 12px; border-radius: 10px; margin-bottom: 8px;
}
#replyBanner.show { display: flex; }
#replyBanner button { margin-left: auto; font-size: 14px; color: var(--muted); }
#replyBanner #replyText {
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: calc(100% - 40px);
}

/* 스레드 패널 */
#app.thread-open { grid-template-columns: 302px 1fr 330px; }
#thread {
  display: flex; flex-direction: column; min-height: 0;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 18px; box-shadow: var(--shadow);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  overflow: hidden; animation: threadIn 0.25s ease;
}
#thread[hidden] { display: none; }
@keyframes threadIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }
.thread-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 13px 15px; border-bottom: 1px solid var(--border); font-size: 14.5px; flex: none;
}
.thread-head button { font-size: 15px; color: var(--muted); padding: 4px 8px; border-radius: 8px; }
.thread-head button:hover { background: var(--panel-2); color: var(--text); }
#threadParent {
  flex: none; margin: 12px 12px 4px; padding: 10px 12px; border-radius: 12px;
  background: color-mix(in srgb, var(--accent) 8%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  font-size: 13px; line-height: 1.5;
}
#threadParent b { display: block; font-size: 12.5px; margin-bottom: 2px; }
#threadMsgs { flex: 1; overflow-y: auto; padding: 8px 12px; }
#threadMsgs .msg .body { max-width: 100%; }
.thread-input-row { display: flex; gap: 7px; padding: 10px 12px 13px; flex: none; }
.thread-input-row textarea {
  flex: 1; resize: none; font-size: 13.5px; min-height: 38px; max-height: 100px;
  background: var(--input-bg); border: 1px solid var(--border);
  border-radius: 10px; padding: 9px 12px; outline: none;
}
.thread-input-row textarea:focus { border-color: var(--accent); }

/* ---------- 프로필 / 아바타 / 채널삭제 ---------- */
.avatar { overflow: hidden; flex: none; }
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }

.profile-box { display: flex; align-items: center; gap: 12px; }
#profileAvatarBtn {
  position: relative; flex: none; border-radius: 50%; padding: 0;
  transition: transform 0.15s;
}
#profileAvatarBtn:hover { transform: scale(1.05); }
#profileAvatarBtn .avatar { border: 2px solid var(--accent); }
#profileAvatarBtn .cam {
  position: absolute; right: -2px; bottom: -2px; font-size: 13px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 50%; width: 22px; height: 22px;
  display: flex; align-items: center; justify-content: center;
}
.profile-edit { flex: 1; min-width: 0; display: flex; gap: 6px; }
.profile-edit input {
  flex: 1; min-width: 0; padding: 9px 11px; font-size: 13px;
  background: var(--input-bg); border: 1px solid var(--border);
  border-radius: 8px; outline: none;
}
.profile-edit input:focus { border-color: var(--accent); }

.room-item-wrap { position: relative; }
.room-item-wrap.manageable .room-item { padding-right: 66px; }
.ch-del {
  display: none; position: absolute; right: 8px; top: 50%;
  transform: translateY(-50%); font-size: 14px; padding: 5px 7px;
  border-radius: 8px; opacity: 0.75;
}
.room-item-wrap:hover .ch-del { display: block; }
.ch-del:hover { opacity: 1; background: color-mix(in srgb, var(--danger) 18%, transparent); }
.ch-edit {
  display: none; position: absolute; right: 38px; top: 50%;
  transform: translateY(-50%); font-size: 13px; padding: 5px 7px;
  border-radius: 8px; opacity: 0.75;
}
.room-item-wrap:hover .ch-edit { display: block; }
.ch-edit:hover { opacity: 1; background: var(--panel-2); }

.ch-editor { padding: 4px 2px; display: flex; flex-direction: column; gap: 6px; }
.ch-editor input {
  width: 100%; padding: 9px 11px; font-size: 13px;
  background: var(--input-bg); border: 1px solid var(--accent);
  border-radius: 8px; outline: none;
}
.ch-editor-btns { display: flex; gap: 6px; }
.ch-editor-btns button {
  flex: 1; font-size: 12.5px; font-weight: 700; padding: 7px;
  border-radius: 8px; background: var(--panel-2); border: 1px solid var(--border);
}
.ch-editor-btns button:hover { border-color: var(--accent); }

/* 멘션 하이라이트 */
.mention {
  font-weight: 700; padding: 1px 6px; border-radius: 7px; white-space: nowrap;
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  color: var(--accent);
}
.mention.me {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: var(--accent-text);
}

/* 차단 */
.blocked-tag {
  font-size: 10px; font-weight: 800; padding: 2px 7px; border-radius: 10px; flex: none;
  background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger);
}
.block-btn:hover { color: var(--danger) !important; border-color: var(--danger) !important; }

/* 위험 구역 */
#ownerZone h4:last-of-type { color: var(--danger); }

/* ---------- 음성통화 ---------- */
.voice-join {
  flex: none; display: inline-flex; align-items: center; gap: 5px;
  font-size: 13px; font-weight: 800; padding: 7px 13px; border-radius: 20px;
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  transition: all 0.2s;
}
.voice-join:hover { border-color: var(--ok); transform: translateY(-1px); }
.voice-join.active {
  background: color-mix(in srgb, var(--ok) 16%, transparent);
  border-color: var(--ok); color: var(--ok);
}
.voice-join[hidden] { display: none; }
.voice-badge {
  font-size: 11px; font-weight: 800; flex: none; padding: 2px 7px; border-radius: 10px;
  background: color-mix(in srgb, var(--ok) 14%, transparent); color: var(--ok);
  animation: voicePulse 2s ease-in-out infinite;
}
@keyframes voicePulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}
.v-peer .avatar { transition: box-shadow 0.15s; }
.v-peer.speaking .avatar {
  box-shadow: 0 0 0 2px var(--ok), 0 0 12px var(--ok);
}
.v-peer.speaking .nm { color: var(--ok); font-weight: 700; }
.v-state { font-size: 14px; flex: none; margin-left: auto; }
.v-peer .dot { margin-left: 0; }
.voice-controls { display: flex; gap: 7px; margin-top: 9px; }
.voice-controls .btn { flex: 1; }

/* 채널 밑 음성 참여자 (디스코드식) */
.v-under { display: flex; flex-direction: column; gap: 3px; margin: 1px 0 5px 30px; }
.v-under-row {
  display: flex; align-items: center; gap: 7px; text-align: left;
  font-size: 12.5px; color: var(--muted); padding: 4px 8px; border-radius: 8px;
  border-left: 2px solid color-mix(in srgb, var(--ok) 55%, transparent);
  transition: background 0.15s, color 0.15s;
}
.v-under-row:hover { background: var(--panel-2); color: var(--text); }
.v-under-nm { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
