/* 케이원 브랜드 테마 (k1sports.kr — 블루 #0088ff / 네이비 #0a1931) */
:root {
  --bg-sidebar: #0a1931;
  --bg-sidebar-hover: #142844;
  --bg-sidebar-active: #1b3252;
  --bg-chat: #1e293b;
  --bg-input: #16202e;
  --bg-modal: #1c2a3f;
  --border: #31435e;
  --text: #e8eaed;
  --text-muted: #8da2bb;
  --accent: #0088ff;
  --accent-dark: #006fd6;
  --danger: #e5534b;
  --badge: #e5534b;
  --bubble-notice: #28344a;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: "Pretendard", "Malgun Gothic", "Apple SD Gothic Neo", sans-serif;
  background: var(--bg-chat);
  color: var(--text);
  overflow: hidden;
}
button { font-family: inherit; cursor: pointer; }
input, textarea, select { font-family: inherit; }
.muted { color: var(--text-muted); font-size: 12px; }
.spacer { flex: 1; }
[hidden] { display: none !important; }

/* ---------- 로그인 ---------- */
#login-view {
  height: 100%; display: flex; align-items: center; justify-content: center;
  background: var(--bg-sidebar);
}
.login-box {
  width: 320px; padding: 36px 28px; background: var(--bg-modal);
  border-radius: 14px; text-align: center; box-shadow: 0 8px 30px rgba(0,0,0,.4);
}
.login-logo { width: 64px; height: 64px; border-radius: 16px; margin-bottom: 12px; }
.login-box h1 { font-size: 19px; margin-bottom: 22px; }
.login-box input {
  width: 100%; padding: 12px 14px; margin-bottom: 10px;
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); font-size: 14px;
}
.login-box input:focus { outline: none; border-color: var(--accent); }
.login-box button {
  width: 100%; padding: 12px; background: var(--accent); border: none;
  border-radius: 8px; color: #fff; font-size: 15px; font-weight: 700;
}
.login-box button:hover { background: var(--accent-dark); }
.login-error { color: var(--danger); font-size: 13px; margin-top: 10px; min-height: 16px; }

/* ---------- 레이아웃 ---------- */
#app-view { display: flex; height: 100%; height: 100dvh; }
#sidebar {
  width: 250px; min-width: 250px; background: var(--bg-sidebar);
  display: flex; flex-direction: column; border-right: 1px solid #000;
}
#chat { flex: 1; display: flex; flex-direction: column; min-width: 0; }

/* ---------- 사이드바 ---------- */
.ws-header {
  display: flex; align-items: center; gap: 8px;
  padding: 14px 16px; font-size: 16px; font-weight: 800;
  border-bottom: 1px solid #142340;
}
.ws-header span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#sidebar-scroll { flex: 1; overflow-y: auto; padding: 8px 0 16px; }
.section { margin-top: 10px; }
.section-header {
  display: flex; align-items: center; padding: 4px 16px 6px;
  font-size: 12px; font-weight: 700; color: var(--text-muted); letter-spacing: .5px;
}
.section-header span { flex: 1; }

.cat-name {
  padding: 8px 16px 3px; font-size: 12px; font-weight: 700; color: var(--text-muted);
  cursor: pointer; user-select: none;
}
.cat-name:hover { color: var(--text); }

.topic-item, .dm-item {
  display: flex; align-items: center; gap: 7px;
  padding: 6px 16px 6px 22px; font-size: 14px; color: #b8bcc4;
  cursor: pointer; user-select: none;
}
.topic-item:hover, .dm-item:hover { background: var(--bg-sidebar-hover); }
.topic-item.active, .dm-item.active { background: var(--bg-sidebar-active); color: #fff; font-weight: 600; }
.topic-item .t-icon { width: 14px; text-align: center; font-size: 12px; color: var(--text-muted); flex: none; }
.topic-item .t-name, .dm-item .t-name {
  flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.topic-item.has-unread .t-name, .dm-item.has-unread .t-name { color: #fff; font-weight: 700; }
.badge {
  background: var(--badge); color: #fff; font-size: 11px; font-weight: 700;
  border-radius: 10px; padding: 1px 7px; flex: none;
}
.online-dot {
  width: 9px; height: 9px; border-radius: 50%; background: #555a61; flex: none;
}
.online-dot.on { background: var(--accent); }

#sidebar-footer {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; border-top: 1px solid #142340;
}
.me-avatar, .msg-avatar {
  width: 34px; height: 34px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 700; color: #fff; flex: none;
}
.me-info { flex: 1; min-width: 0; }
#me-name { font-size: 13px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.icon-btn {
  background: none; border: none; color: var(--text-muted);
  font-size: 16px; padding: 4px 6px; border-radius: 6px; line-height: 1;
}
.icon-btn:hover { background: var(--bg-sidebar-hover); color: var(--text); }

/* ---------- 채팅 ---------- */
#chat-empty { flex: 1; display: flex; align-items: center; justify-content: center; }
.empty-inner { text-align: center; color: var(--text-muted); font-size: 15px; line-height: 2.2; }

#chat-room { flex: 1; display: flex; flex-direction: column; min-height: 0; }
#chat-header {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 18px; border-bottom: 1px solid var(--border);
  font-size: 15px; font-weight: 700; flex: none;
}
#chat-icon { color: var(--text-muted); font-size: 13px; }
#chat-members { font-weight: 400; }

#messages { flex: 1; overflow-y: auto; padding: 14px 18px; }

.date-divider {
  display: flex; align-items: center; gap: 12px;
  margin: 18px 0 10px; color: var(--text-muted); font-size: 12px;
}
.date-divider::before, .date-divider::after {
  content: ""; flex: 1; height: 1px; background: var(--border);
}

.msg-group { display: flex; gap: 10px; margin-top: 14px; }
.msg-group.cont { margin-top: 2px; }
.msg-group.cont .msg-avatar, .msg-group.cont .msg-head { display: none; }
.msg-group.cont .msg-body { margin-left: 44px; }
.msg-body { min-width: 0; flex: 1; }
.msg-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 3px; }
.msg-name { font-size: 14px; font-weight: 700; }
.msg-time { font-size: 11px; color: var(--text-muted); }
.msg-line { display: flex; align-items: flex-end; gap: 8px; }
.msg-main { min-width: 0; }
.msg-side { display: flex; align-items: center; gap: 6px; flex: none; }
.msg-group.highlight { background: rgba(0, 136, 255, .12); border-radius: 8px; transition: background .3s; }

/* 답장 인용 */
.msg-quote {
  font-size: 12px; color: var(--text-muted); cursor: pointer;
  border-left: 2px solid var(--accent); padding: 2px 8px; margin-bottom: 3px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 480px;
}
.msg-quote:hover { color: var(--text); }
.msg-quote b { color: #6fb3ff; }

/* 안읽음 숫자 */
.msg-unread {
  background: none; border: none; color: var(--accent);
  font-size: 11px; font-weight: 800; padding: 2px 4px; cursor: default;
}
.msg-unread.clickable { cursor: pointer; }
.msg-unread.clickable:hover { text-decoration: underline; }

/* 반응 칩 */
.msg-reactions { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px; }
.react-chip {
  background: var(--bg-input); border: 1px solid var(--border); border-radius: 12px;
  color: var(--text); font-size: 12px; padding: 2px 9px; cursor: pointer;
}
.react-chip:hover { border-color: var(--accent); }
.react-chip.mine { background: rgba(0, 136, 255, .18); border-color: var(--accent); }

/* 메시지 액션 버튼 */
.msg-actions { display: flex; gap: 2px; visibility: hidden; }
.msg-line:hover .msg-actions { visibility: visible; }
.msg-actions button {
  background: none; border: none; color: var(--text-muted);
  font-size: 13px; padding: 2px 5px; border-radius: 5px; cursor: pointer;
}
.msg-actions button:hover { background: var(--bg-sidebar-hover); color: var(--text); }
@media (hover: none) {
  .msg-actions { visibility: visible; opacity: .55; }
}

/* 답장 입력 바 */
#reply-bar {
  display: flex; align-items: center; gap: 8px;
  margin: 0 18px 6px; padding: 7px 12px;
  background: var(--bg-input); border-left: 3px solid var(--accent);
  border-radius: 8px; font-size: 12px; color: var(--text-muted); flex: none;
}
#reply-bar-text { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#reply-bar b { color: #6fb3ff; }

/* 반응 선택창 */
#react-picker {
  position: fixed; z-index: 300; display: flex; gap: 2px;
  background: var(--bg-modal); border: 1px solid var(--border); border-radius: 22px;
  padding: 5px 8px; box-shadow: 0 6px 20px rgba(0,0,0,.45);
}
#react-picker button {
  background: none; border: none; font-size: 19px; padding: 3px 6px;
  border-radius: 50%; cursor: pointer;
}
#react-picker button:hover { background: var(--bg-sidebar-hover); transform: scale(1.18); }
.msg-content {
  font-size: 14px; line-height: 1.55; white-space: pre-wrap; word-break: break-word;
  max-width: 720px;
}
.msg-content a { color: #6ab7ff; }
.msg-content img.msg-image {
  max-width: min(360px, 80%); max-height: 300px; border-radius: 8px;
  display: block; margin-top: 4px; cursor: pointer;
}
.file-card {
  display: inline-flex; align-items: center; gap: 10px; margin-top: 4px;
  padding: 10px 14px; background: var(--bg-input); border: 1px solid var(--border);
  border-radius: 10px; color: var(--text); text-decoration: none; font-size: 13px;
}
.file-card:hover { border-color: var(--accent); }
.msg-actions .msg-del:hover { color: var(--danger); }

/* ---------- 입력창 ---------- */
#composer {
  display: flex; align-items: flex-end; gap: 8px;
  margin: 0 18px; padding: 8px 10px;
  background: var(--bg-input); border: 1px solid var(--border); border-radius: 12px;
}
#composer:focus-within { border-color: var(--accent); }
#msg-input {
  flex: 1; background: none; border: none; resize: none;
  color: var(--text); font-size: 14px; line-height: 1.5; max-height: 140px;
  padding: 6px 2px;
}
#msg-input:focus { outline: none; }
#btn-send {
  background: var(--accent); border: none; color: #fff;
  width: 34px; height: 34px; border-radius: 8px; font-size: 15px; flex: none;
}
#btn-send:hover { background: var(--accent-dark); }
.composer-hint { padding: 5px 22px 10px; flex: none; }

/* ---------- 모달 ---------- */
#modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.55);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
#modal {
  width: min(560px, 94vw); max-height: 86vh; overflow-y: auto;
  background: var(--bg-modal); border-radius: 14px; padding: 22px 24px;
  box-shadow: 0 10px 40px rgba(0,0,0,.5);
}
#modal h2 { font-size: 17px; margin-bottom: 16px; }
#modal h3 { font-size: 14px; margin: 18px 0 8px; color: var(--text-muted); }
.modal-tabs { display: flex; gap: 6px; margin-bottom: 16px; }
.modal-tabs button {
  padding: 7px 14px; border-radius: 8px; border: 1px solid var(--border);
  background: none; color: var(--text-muted); font-size: 13px; font-weight: 600;
}
.modal-tabs button.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.form-row { display: flex; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.form-row input, .form-row select {
  flex: 1; min-width: 110px; padding: 9px 12px;
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); font-size: 13px;
}
.form-row input:focus, .form-row select:focus { outline: none; border-color: var(--accent); }
.form-row label.check {
  display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text);
  padding: 9px 4px;
}
.btn-primary {
  padding: 9px 18px; background: var(--accent); border: none;
  border-radius: 8px; color: #fff; font-size: 13px; font-weight: 700;
}
.btn-primary:hover { background: var(--accent-dark); }
.btn-ghost {
  padding: 9px 14px; background: none; border: 1px solid var(--border);
  border-radius: 8px; color: var(--text-muted); font-size: 13px;
}
.btn-ghost:hover { color: var(--text); border-color: var(--text-muted); }
.btn-danger-ghost {
  background: none; border: none; color: var(--danger); font-size: 12px; padding: 4px 8px;
}
.list-row {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 4px; border-bottom: 1px solid #3a3d4233; font-size: 13px;
}
.list-row .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.member-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 4px; margin: 8px 0;
}
.member-grid label {
  display: flex; align-items: center; gap: 6px; font-size: 13px;
  padding: 5px 8px; border-radius: 6px; cursor: pointer;
}
.member-grid label:hover { background: var(--bg-sidebar-hover); }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

.lvl-chip {
  font-size: 11px; padding: 1px 8px; border-radius: 8px;
  background: var(--bg-input); border: 1px solid var(--border); color: var(--text-muted); flex: none;
}

/* ---------- 토스트 ---------- */
#toast-container {
  position: fixed; top: 14px; right: 14px; z-index: 200;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  background: var(--bg-modal); border: 1px solid var(--border); border-left: 3px solid var(--accent);
  border-radius: 10px; padding: 12px 16px; max-width: 320px;
  box-shadow: 0 6px 20px rgba(0,0,0,.4); cursor: pointer;
  animation: slideIn .2s ease;
}
.toast .t-title { font-size: 13px; font-weight: 700; margin-bottom: 2px; }
.toast .t-body { font-size: 12px; color: var(--text-muted); }
@keyframes slideIn { from { transform: translateX(30px); opacity: 0; } }

/* ---------- 스크롤바 ---------- */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-thumb { background: #3a4d6b; border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- 모바일 ---------- */
.mobile-only { display: none; }
@media (max-width: 760px) {
  .mobile-only { display: inline-block; }
  #sidebar { width: 100%; min-width: 100%; }
  #chat { display: none; }
  body.mobile-chat #sidebar { display: none; }
  body.mobile-chat #chat { display: flex; }
  .composer-hint { display: none; }
  #composer { margin: 0 10px 10px; }
  #messages { padding: 12px; }
}
