/* Hoppers 웹 클라이언트 — 다크 앰비언트. 방마다 서버 테마색이 포인트로 흐른다. */

:root {
  --bg: #0e1113;
  --panel: #14191d;
  --panel-2: #1a2026;
  --line: rgba(255, 255, 255, 0.07);
  --text: #e9eef2;
  --muted: #93a1ad;
  --accent: #6ee7b7;
  --accent-dim: rgba(110, 231, 183, 0.14);
  --danger: #f87171;
  --room: var(--accent); /* 현재 방 테마색으로 덮어씀 */
  --radius: 14px;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont,
    "Apple SD Gothic Neo", "Noto Sans KR", "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
input, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }

/* ===== 로그인 ===== */

.auth-view {
  height: 100%;
  display: grid;
  place-items: center;
  background:
    radial-gradient(600px 300px at 20% 10%, rgba(110, 231, 183, 0.06), transparent),
    radial-gradient(500px 300px at 85% 85%, rgba(125, 160, 255, 0.05), transparent),
    var(--bg);
}

.auth-card {
  width: min(360px, calc(100vw - 40px));
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 32px 28px;
  text-align: center;
}

.auth-logo { font-size: 44px; }
.auth-card h1 { margin: 6px 0 2px; font-size: 26px; letter-spacing: 0.5px; }
.auth-tagline { margin: 0 0 20px; color: var(--muted); font-size: 13px; }

.auth-tabs {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px;
  background: var(--bg); border-radius: 10px; padding: 4px; margin-bottom: 18px;
}
.auth-tab { padding: 8px; border-radius: 8px; color: var(--muted); }
.auth-tab.active { background: var(--panel-2); color: var(--text); }

#auth-form { display: grid; gap: 12px; text-align: left; }
#auth-form label { display: grid; gap: 6px; font-size: 12.5px; color: var(--muted); }
#auth-form input {
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; outline: none;
}
#auth-form input:focus { border-color: var(--accent); }

.btn-primary {
  background: var(--accent); color: #08281b; font-weight: 700;
  border-radius: 10px; padding: 11px; margin-top: 4px;
}
.btn-primary:disabled { opacity: 0.6; cursor: wait; }
.auth-error { min-height: 1.2em; margin: 2px 0 0; color: var(--danger); font-size: 13px; }

/* ===== 레이아웃 ===== */

.main-view {
  height: 100dvh;
  display: grid;
  grid-template-columns: 280px 1fr auto;
  overflow: hidden;
}

/* ===== 사이드바 ===== */

.sidebar {
  display: flex; flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--line);
  min-width: 0;
}

.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 16px 10px;
}
.brand { font-weight: 800; letter-spacing: 0.3px; }
.conn-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--danger); transition: background 0.3s;
}
.conn-dot.on { background: var(--accent); }

.room-list { flex: 1; overflow-y: auto; padding: 4px 8px; }

.room-item {
  display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center;
  width: 100%; text-align: left;
  padding: 10px 10px; border-radius: 12px; margin-bottom: 2px;
  border-left: 3px solid transparent;
}
.room-item:hover { background: rgba(255, 255, 255, 0.04); }
.room-item.active { background: var(--panel-2); border-left-color: var(--room-color, var(--accent)); }

.room-swatch {
  width: 34px; height: 34px; border-radius: 10px; flex: none;
  display: grid; place-items: center; font-size: 17px;
  background: color-mix(in srgb, var(--room-color, var(--accent)) 22%, transparent);
}

.room-item-main { min-width: 0; }
.room-item-name { display: flex; gap: 6px; align-items: baseline; }
.room-item-name b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-item-time { color: var(--muted); font-size: 11px; flex: none; margin-left: auto; }
.room-item-preview {
  color: var(--muted); font-size: 12.5px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.unread-badge {
  background: var(--room-color, var(--accent)); color: #0b1512;
  min-width: 20px; height: 20px; border-radius: 10px;
  display: grid; place-items: center;
  font-size: 11px; font-weight: 800; padding: 0 6px;
}

.sidebar-actions { display: grid; gap: 4px; padding: 8px; border-top: 1px solid var(--line); }
.btn-ghost {
  text-align: left; padding: 9px 12px; border-radius: 10px; color: var(--muted);
}
.btn-ghost:hover { background: rgba(255, 255, 255, 0.05); color: var(--text); }

.sidebar-me {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 16px; border-top: 1px solid var(--line); font-size: 13px;
}
.me-name { color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.btn-link { color: var(--muted); font-size: 12.5px; }
.btn-link:hover { color: var(--danger); }

/* ===== 채팅 ===== */

.chat { display: flex; flex-direction: column; min-width: 0; position: relative; }

.chat-empty {
  flex: 1; display: grid; place-content: center; gap: 8px;
  color: var(--muted); text-align: center;
}
.chat-empty-art { font-size: 42px; letter-spacing: 6px; }

.chat-room { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.chat-header {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--room-color, transparent) 5%, var(--bg));
}
.chat-title { min-width: 0; flex: 1; }
.chat-title h2 { margin: 0; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-sub { color: var(--muted); font-size: 12px; }
.chat-header-actions { display: flex; gap: 4px; }

.btn-icon {
  width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center;
  font-size: 15px;
}
.btn-icon:hover { background: rgba(255, 255, 255, 0.06); }

.messages {
  flex: 1; overflow-y: auto; padding: 16px 16px 6px;
  display: flex; flex-direction: column; gap: 2px;
  outline: none;
  overscroll-behavior: contain;
}

.day-divider {
  align-self: center; margin: 14px 0 8px;
  color: var(--muted); font-size: 11.5px;
  background: var(--panel); border: 1px solid var(--line);
  padding: 3px 12px; border-radius: 999px;
}

.msg { display: grid; grid-template-columns: 38px 1fr; gap: 10px; padding: 3px 0; min-width: 0; }
.msg.mine { grid-template-columns: 1fr; }
.msg.continued { margin-top: -2px; }

.msg-avatar {
  width: 34px; height: 34px; border-radius: 50%; flex: none;
  display: grid; place-items: center; font-size: 18px;
  background: var(--panel-2); border: 1px solid var(--line);
  position: relative;
  user-select: none;
}
.msg.continued .msg-avatar { visibility: hidden; height: 0; }
.presence-dot {
  position: absolute; right: -1px; bottom: -1px;
  width: 10px; height: 10px; border-radius: 50%;
  border: 2px solid var(--bg); background: #566270;
}
.presence-dot.on { background: var(--accent); }

.msg-body { min-width: 0; }
.msg-meta { display: flex; align-items: baseline; gap: 8px; }
.msg.continued .msg-meta { display: none; }
.msg-author { font-size: 13px; font-weight: 700; color: color-mix(in srgb, var(--room-color, var(--accent)) 70%, var(--text)); }
.msg-time { color: var(--muted); font-size: 10.5px; }

.msg-row { display: flex; align-items: flex-end; gap: 6px; }
.msg.mine .msg-row { flex-direction: row-reverse; }

.bubble {
  max-width: min(560px, 78%);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 4px 14px 14px 14px;
  padding: 7px 12px;
  white-space: pre-wrap; word-break: break-word;
  position: relative;
}
.msg.continued .bubble { border-radius: 14px; }
.msg.mine .bubble {
  background: color-mix(in srgb, var(--room-color, var(--accent)) 16%, var(--panel-2));
  border-radius: 14px 4px 14px 14px;
}
.msg.mine.continued .bubble { border-radius: 14px; }
.bubble.pending { opacity: 0.55; }
.bubble.deleted { color: var(--muted); font-style: italic; background: transparent; border-style: dashed; }
.edited-mark { color: var(--muted); font-size: 10.5px; margin-left: 6px; }

.msg-side { display: flex; gap: 2px; opacity: 0; transition: opacity 0.12s; flex: none; }
.msg-row:hover .msg-side { opacity: 1; }
.msg-side button {
  width: 26px; height: 26px; border-radius: 8px; font-size: 13px;
  display: grid; place-items: center; color: var(--muted);
}
.msg-side button:hover { background: rgba(255, 255, 255, 0.07); color: var(--text); }

.reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.msg.mine .reactions { justify-content: flex-end; }
.reaction-chip {
  display: inline-flex; gap: 5px; align-items: center;
  border: 1px solid var(--line); background: var(--panel);
  border-radius: 999px; padding: 2px 8px; font-size: 12.5px;
}
.reaction-chip:hover { border-color: var(--muted); }
.reaction-chip.mine {
  border-color: color-mix(in srgb, var(--room-color, var(--accent)) 70%, transparent);
  background: color-mix(in srgb, var(--room-color, var(--accent)) 14%, var(--panel));
}
.reaction-chip b { font-weight: 700; font-size: 11.5px; }

.read-marker { color: var(--muted); font-size: 10px; text-align: right; margin-top: 1px; }

.emoji-pop {
  position: absolute; z-index: 30;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow); padding: 8px;
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 2px;
}
.emoji-pop button { font-size: 19px; padding: 6px 8px; border-radius: 8px; }
.emoji-pop button:hover { background: rgba(255, 255, 255, 0.08); }

.edit-box { display: grid; gap: 6px; }
.edit-box textarea {
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 10px; outline: none; resize: vertical; min-width: 240px;
}
.edit-box-actions { display: flex; gap: 8px; justify-content: flex-end; font-size: 12px; }
.edit-box-actions .save { color: var(--accent); font-weight: 700; }
.edit-box-actions .cancel { color: var(--muted); }

.inline-confirm { display: inline-flex; gap: 8px; align-items: center; font-size: 12.5px; }
.inline-confirm .yes { color: var(--danger); font-weight: 700; }
.inline-confirm .no { color: var(--muted); }

.typing { min-height: 20px; padding: 0 18px 2px; color: var(--muted); font-size: 12px; }
.typing .dots::after { content: "…"; animation: blink 1.2s infinite; }
@keyframes blink { 50% { opacity: 0.25; } }

.composer {
  display: flex; gap: 8px; align-items: flex-end;
  padding: 10px 14px 14px; border-top: 1px solid var(--line);
}
.composer textarea {
  flex: 1; resize: none; max-height: 140px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 10px 14px; outline: none;
}
.composer textarea:focus { border-color: color-mix(in srgb, var(--room-color, var(--accent)) 60%, var(--line)); }
.btn-send {
  width: 42px; height: 42px; border-radius: 50%; flex: none;
  background: var(--room-color, var(--accent)); color: #0b1512; font-size: 16px; font-weight: 800;
}
.btn-send:disabled { opacity: 0.4; }

/* 새 메시지 점프 버튼 */
.jump-latest {
  position: absolute; right: 20px; bottom: 86px; z-index: 5;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px;
  padding: 7px 14px; font-size: 12.5px; box-shadow: var(--shadow);
}

/* ===== 멤버 패널 ===== */

.members-panel {
  width: 260px; background: var(--panel); border-left: 1px solid var(--line);
  display: flex; flex-direction: column;
}
.panel-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 16px; border-bottom: 1px solid var(--line);
}
.panel-header h3 { margin: 0; font-size: 14px; }

.member-list { list-style: none; margin: 0; padding: 8px; overflow-y: auto; flex: 1; }
.member-item {
  display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center;
  padding: 8px 10px; border-radius: 12px;
}
.member-item:hover { background: rgba(255, 255, 255, 0.04); }
.member-avatar {
  width: 34px; height: 34px; border-radius: 50%; position: relative;
  display: grid; place-items: center; font-size: 18px;
  background: var(--panel-2); border: 1px solid var(--line);
}
.member-name { min-width: 0; font-size: 13.5px; }
.member-name b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.member-name small { color: var(--muted); font-size: 11px; }
.member-actions { display: flex; gap: 2px; opacity: 0; transition: opacity 0.12s; }
.member-item:hover .member-actions { opacity: 1; }
.member-actions button {
  width: 26px; height: 26px; border-radius: 8px; font-size: 13px;
  display: grid; place-items: center;
}
.member-actions button:hover { background: rgba(255, 255, 255, 0.08); }

@keyframes wobble {
  0%, 100% { transform: translateX(0) rotate(0); }
  15% { transform: translateX(-7px) rotate(-1.2deg); }
  30% { transform: translateX(6px) rotate(1deg); }
  45% { transform: translateX(-5px) rotate(-0.8deg); }
  60% { transform: translateX(4px) rotate(0.6deg); }
  75% { transform: translateX(-2px) rotate(-0.3deg); }
}
.wobble { animation: wobble 0.7s ease-in-out; }
@keyframes avatar-hop {
  0%, 100% { transform: translateY(0); }
  40% { transform: translateY(-7px); }
  70% { transform: translateY(2px); }
}
.hop { animation: avatar-hop 0.5s ease-in-out 2; }

/* ===== 모달 ===== */

.modal-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0, 0, 0, 0.55);
  display: grid; place-items: center;
  backdrop-filter: blur(2px);
}
.modal {
  width: min(400px, calc(100vw - 36px));
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 18px; box-shadow: var(--shadow);
  padding: 22px;
}
.modal h3 { margin: 0 0 14px; font-size: 16px; }
.modal form, .modal .modal-body { display: grid; gap: 12px; }
.modal label { display: grid; gap: 6px; font-size: 12.5px; color: var(--muted); }
.modal input {
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; outline: none;
}
.modal input:focus { border-color: var(--accent); }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 6px; }
.modal-actions .btn-secondary { color: var(--muted); padding: 9px 14px; border-radius: 10px; }
.modal-actions .btn-secondary:hover { background: rgba(255,255,255,0.05); color: var(--text); }
.modal-actions .btn-primary { padding: 9px 16px; margin: 0; }
.modal-actions .danger { background: var(--danger); color: #2b0808; }
.modal .code-view {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: var(--bg); border: 1px dashed var(--line); border-radius: 10px;
  padding: 10px 14px; font-family: ui-monospace, monospace; font-size: 18px; letter-spacing: 3px;
}
.modal .menu { display: grid; gap: 2px; }
.modal .menu button {
  text-align: left; padding: 11px 12px; border-radius: 10px;
}
.modal .menu button:hover { background: rgba(255, 255, 255, 0.05); }
.modal .menu button.danger { color: var(--danger); }
.modal .hint { color: var(--muted); font-size: 12px; margin: 0; }

/* ===== 토스트 ===== */

.toasts {
  position: fixed; top: 14px; left: 50%; transform: translateX(-50%);
  z-index: 100; display: grid; gap: 8px; justify-items: center;
  pointer-events: none;
}
.toast {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow); padding: 9px 16px; font-size: 13.5px;
  animation: toast-in 0.25s ease-out;
}
.toast.error { border-color: color-mix(in srgb, var(--danger) 45%, transparent); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } }

/* ===== 모바일 ===== */

.only-mobile { display: none !important; }

@media (max-width: 860px) {
  .main-view { grid-template-columns: 1fr; }
  .sidebar { position: absolute; inset: 0; z-index: 20; border-right: none; }
  .main-view.in-room .sidebar { display: none; }
  .main-view:not(.in-room) .chat { display: none; }
  .only-mobile { display: grid !important; }
  .members-panel {
    position: absolute; right: 0; top: 0; bottom: 0; z-index: 25;
    box-shadow: var(--shadow);
  }
  .bubble { max-width: 82%; }
  .msg-side { opacity: 1; }
}
