:root {
  --chat-bg: #f5f7fb;
  --chat-surface: #ffffff;
  --chat-surface-soft: #f8fafc;
  --chat-line: #dde3ec;
  --chat-text: #172033;
  --chat-muted: #687386;
  --chat-primary: #3157d5;
  --chat-primary-dark: #2444ae;
  --chat-success: #15815d;
  --chat-danger: #bd2d3a;
  --chat-shadow: 0 18px 50px rgba(31, 45, 75, 0.10);
  --chat-radius: 20px;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body.chat-page {
  margin: 0;
  background:
    radial-gradient(circle at 10% 0%, rgba(49, 87, 213, 0.09), transparent 28rem),
    var(--chat-bg);
  color: var(--chat-text);
  font-family: Pretendard, "Noto Sans KR", "Apple SD Gothic Neo", system-ui, sans-serif;
}

button, textarea, input { font: inherit; }

button, a { -webkit-tap-highlight-color: transparent; }

.chat-skip-link {
  position: fixed;
  left: 1rem;
  top: -5rem;
  z-index: 1000;
  padding: .75rem 1rem;
  border-radius: .75rem;
  background: #111827;
  color: white;
}
.chat-skip-link:focus { top: 1rem; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.chat-topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  border-bottom: 1px solid rgba(221, 227, 236, .85);
  background: rgba(255, 255, 255, .90);
  backdrop-filter: blur(14px);
}

.chat-topbar__inner {
  width: min(1180px, calc(100% - 32px));
  min-height: 72px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.chat-brand {
  display: inline-flex;
  align-items: center;
  gap: .75rem;
  color: inherit;
  text-decoration: none;
}

.chat-brand__mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: linear-gradient(145deg, var(--chat-primary), #6682e8);
  color: #fff;
  font-weight: 800;
  box-shadow: 0 8px 20px rgba(49, 87, 213, .25);
}

.chat-brand strong,
.chat-brand small { display: block; }

.chat-brand small {
  margin-top: .08rem;
  color: var(--chat-muted);
  font-size: .78rem;
}

.chat-connection {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  padding: .48rem .72rem;
  border: 1px solid var(--chat-line);
  border-radius: 999px;
  background: #fff;
  color: var(--chat-muted);
  font-size: .82rem;
}

.chat-connection__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #9aa4b2;
}

.chat-connection[data-state="connected"] .chat-connection__dot {
  background: var(--chat-success);
  box-shadow: 0 0 0 4px rgba(21, 129, 93, .12);
}

.chat-connection[data-state="error"] .chat-connection__dot {
  background: var(--chat-danger);
}


.chat-topbar__actions {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: .75rem;
  min-width: 0;
}

.chat-navigation {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
}

.chat-navigation__button {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .32rem;
  padding: .55rem .78rem;
  border: 1px solid var(--chat-line);
  border-radius: 11px;
  background: #fff;
  color: var(--chat-primary-dark);
  font-size: .82rem;
  font-weight: 800;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(31, 45, 75, .06);
}

.chat-navigation__button:hover,
.chat-navigation__button:focus-visible {
  border-color: rgba(49, 87, 213, .48);
  background: #f4f6ff;
  outline: none;
}

.chat-navigation__button--exit {
  border-color: rgba(189, 45, 58, .24);
  color: #a12632;
  background: #fff8f8;
}

.chat-navigation__button--exit:hover,
.chat-navigation__button--exit:focus-visible {
  border-color: rgba(189, 45, 58, .48);
  background: #fff0f1;
}

.chat-main {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 48px;
}

.public-chat {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

.public-chat__sidebar {
  display: grid;
  gap: 16px;
  position: sticky;
  top: 100px;
}

.chat-panel {
  border: 1px solid rgba(221, 227, 236, .92);
  border-radius: var(--chat-radius);
  background: var(--chat-surface);
  box-shadow: var(--chat-shadow);
}

.chat-room-card,
.chat-policy-card { padding: 22px; }

.chat-eyebrow {
  margin: 0 0 .4rem;
  color: var(--chat-primary);
  font-size: .74rem;
  font-weight: 800;
  letter-spacing: .11em;
}

.chat-room-card h1,
.public-chat__header h2 {
  margin: 0;
  letter-spacing: -.03em;
}

.chat-room-card h1 { font-size: 1.45rem; }

.chat-room-card p:not(.chat-eyebrow),
.chat-policy-card li,
.chat-login-notice p {
  color: var(--chat-muted);
  line-height: 1.65;
}

.chat-policy-card h2 {
  margin: 0 0 .7rem;
  font-size: 1rem;
}

.chat-policy-card ul {
  margin: 0;
  padding-left: 1.2rem;
}

.chat-policy-card li + li { margin-top: .45rem; }

.public-chat__conversation {
  min-height: calc(100vh - 148px);
  overflow: hidden;
  display: grid;
  grid-template-rows: auto auto minmax(340px, 1fr) auto auto;
}

.public-chat__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 20px 22px;
  border-bottom: 1px solid var(--chat-line);
}

.public-chat__header h2 { font-size: 1.25rem; }

.public-chat__header-tools {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.chat-order-hint {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: .35rem .62rem;
  border: 1px solid #d7deea;
  border-radius: 999px;
  background: #f8fafc;
  color: #526075;
  font-size: .74rem;
  font-weight: 800;
  white-space: nowrap;
}

.chat-role-badge {
  flex: 0 0 auto;
  padding: .42rem .68rem;
  border-radius: 999px;
  background: #eef2ff;
  color: var(--chat-primary-dark);
  font-size: .78rem;
  font-weight: 700;
}

.chat-load-older {
  min-height: 44px;
  display: grid;
  place-items: center;
  padding: 8px 16px;
}

.chat-load-older--bottom {
  border-top: 1px solid #eef1f5;
  background: #fbfcfe;
}

.chat-message-list {
  min-height: 0;
  max-height: calc(100vh - 360px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 14px 22px 22px;
  scroll-behavior: smooth;
}

.chat-empty {
  min-height: 260px;
  display: grid;
  place-content: center;
  gap: .4rem;
  text-align: center;
  color: var(--chat-muted);
}

.chat-empty strong { color: var(--chat-text); }

.chat-message {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr);
  gap: 12px;
  padding: 13px 0;
}

.chat-message + .chat-message { border-top: 1px solid #f0f2f6; }

.chat-message__avatar {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 13px;
  background: #edf1ff;
  color: var(--chat-primary-dark);
  font-weight: 800;
}

.chat-message__content { min-width: 0; }

.chat-message__meta {
  display: flex;
  align-items: baseline;
  gap: .55rem;
  min-width: 0;
}

.chat-message__meta strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: .92rem;
}

.chat-message__meta time {
  flex: 0 0 auto;
  color: var(--chat-muted);
  font-size: .72rem;
}

.chat-message__content p {
  margin: .3rem 0 0;
  color: #263248;
  font-size: .96rem;
  line-height: 1.68;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.chat-new-message-notice {
  position: relative;
  height: 0;
  z-index: 2;
  text-align: center;
}

.chat-new-message-notice button {
  transform: translateY(8px);
  border: 1px solid #cbd5e1;
  border-radius: 999px;
  padding: .48rem .82rem;
  background: #fff;
  color: var(--chat-primary-dark);
  box-shadow: 0 7px 22px rgba(31, 45, 75, .16);
  cursor: pointer;
}

.chat-composer {
  border-top: 1px solid var(--chat-line);
  padding: 16px 20px 18px;
  background: var(--chat-surface-soft);
}

.chat-composer textarea {
  width: 100%;
  min-height: 66px;
  max-height: 150px;
  resize: vertical;
  border: 1px solid #cfd6e2;
  border-radius: 14px;
  padding: 12px 14px;
  background: #fff;
  color: var(--chat-text);
  line-height: 1.5;
  outline: none;
}

.chat-composer textarea:focus {
  border-color: var(--chat-primary);
  box-shadow: 0 0 0 4px rgba(49, 87, 213, .10);
}

.chat-composer textarea:disabled {
  background: #eef1f5;
  cursor: not-allowed;
}

.chat-composer__footer {
  margin-top: 10px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: .8rem;
}

.chat-character-count {
  color: var(--chat-muted);
  font-size: .78rem;
}

.chat-form-status {
  min-height: 1.1rem;
  margin: .5rem 0 0;
  color: var(--chat-muted);
  font-size: .8rem;
}

.chat-form-status[data-kind="error"] { color: var(--chat-danger); }
.chat-form-status[data-kind="success"] { color: var(--chat-success); }

.chat-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  border: 0;
  border-radius: 12px;
  padding: .65rem 1rem;
  font-weight: 750;
  text-decoration: none;
  cursor: pointer;
}

.chat-button:disabled {
  opacity: .55;
  cursor: not-allowed;
}

.chat-button--primary {
  background: var(--chat-primary);
  color: #fff;
}

.chat-button--primary:hover:not(:disabled) { background: var(--chat-primary-dark); }

.chat-button--quiet {
  min-height: 34px;
  background: transparent;
  color: var(--chat-primary-dark);
  font-size: .82rem;
}

.chat-login-notice {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  border-top: 1px solid var(--chat-line);
  padding: 16px 20px;
  background: var(--chat-surface-soft);
}

.chat-login-notice strong,
.chat-login-notice p { display: block; }

.chat-login-notice p { margin: .25rem 0 0; font-size: .84rem; }

.chat-toast-region {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 100;
  width: min(360px, calc(100% - 36px));
  display: grid;
  gap: 8px;
}

.chat-toast {
  border: 1px solid var(--chat-line);
  border-radius: 12px;
  padding: 12px 14px;
  background: #fff;
  box-shadow: var(--chat-shadow);
  line-height: 1.45;
}

.chat-toast[data-kind="error"] { border-color: #f3b9bf; }

@media (max-width: 860px) {
  .chat-main { width: min(100% - 20px, 760px); padding-top: 14px; }
  .public-chat { grid-template-columns: 1fr; }

  /* 태블릿·모바일에서는 채팅 본문을 가이드보다 먼저 보여준다. */
  .public-chat__conversation {
    order: 1;
    min-height: calc(100vh - 120px);
  }
  .public-chat__sidebar {
    order: 2;
    position: static;
    grid-template-columns: 1fr 1fr;
  }
  .chat-message-list {
    max-height: 62vh;
    -webkit-overflow-scrolling: touch;
  }
}

@media (max-width: 620px) {
  html,
  body.chat-page {
    width: 100%;
    height: 100%;
    min-height: 100%;
    overflow-x: hidden;
  }

  .chat-topbar__inner { width: calc(100% - 20px); min-height: 64px; gap: .55rem; }
  .chat-brand { gap: .5rem; }
  .chat-brand__mark { width: 34px; height: 34px; }
  .chat-brand small { display: none; }
  .chat-topbar__actions { gap: .4rem; }
  .chat-connection { display: none; }
  .chat-navigation { gap: .32rem; }
  .chat-navigation__button {
    min-height: 36px;
    padding: .5rem .62rem;
    border-radius: 10px;
    font-size: .76rem;
  }

  .chat-main {
    width: 100%;
    min-height: calc(100dvh - 64px);
    padding: 0;
  }

  .public-chat {
    width: 100%;
    min-height: calc(100dvh - 64px);
    gap: 0;
  }

  /* 작은 모바일에서는 가이드가 채팅을 가리지 않도록 대화창만 우선 노출한다. */
  .public-chat__sidebar { display: none; }

  .public-chat__conversation {
    order: 1;
    width: 100%;
    height: calc(100dvh - 64px);
    min-height: 0;
    max-height: none;
    overflow: hidden;
    grid-template-rows: auto minmax(0, 1fr) auto auto auto;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .public-chat__header {
    padding: 13px 14px;
    gap: 8px;
  }

  .public-chat__header h2 { font-size: 1.08rem; }

  .public-chat__header-tools {
    gap: 5px;
  }

  .chat-order-hint,
  .chat-role-badge {
    font-size: .68rem;
    padding: .3rem .5rem;
  }

  .chat-message-list {
    min-height: 0;
    max-height: none;
    overflow-y: auto;
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
    padding: 8px 14px 14px;
  }

  .chat-message {
    grid-template-columns: 34px minmax(0, 1fr);
    gap: 9px;
    padding: 11px 0;
  }

  .chat-message__avatar {
    width: 34px;
    height: 34px;
    border-radius: 11px;
  }

  .chat-message__content p {
    font-size: .94rem;
    line-height: 1.62;
  }

  .chat-load-older {
    min-height: 38px;
    padding: 5px 12px;
  }

  .chat-new-message-notice button {
    transform: translateY(6px);
  }

  .chat-composer, .chat-login-notice {
    position: relative;
    bottom: auto;
    z-index: 4;
    padding-left: 14px;
    padding-right: 14px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }

  .chat-composer textarea {
    min-height: 56px;
    max-height: 110px;
  }

  .chat-login-notice { align-items: stretch; flex-direction: column; }
  .chat-login-notice .chat-button { width: 100%; }
  .chat-connection { padding: .4rem .55rem; }
  .chat-connection span:last-child { max-width: 92px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; }
}


/* [PUBLIC CHAT POLICY 20260725] 이용규칙 동의·입장불허 */
.chat-policy-card--important {
  border-color: rgba(189,45,58,.28);
  border-left: 5px solid var(--chat-danger);
  background: linear-gradient(180deg, #fff, #fff8f8);
}
.chat-policy-card--important h2 { margin-top: 0; }
.chat-policy-card--important ul { padding-left: 1.15rem; }
.chat-policy-card--important li { margin: .45rem 0; line-height: 1.55; }
.chat-policy-state { display:flex;align-items:center;gap:.45rem;flex-wrap:wrap;margin-top:12px;padding-top:12px;border-top:1px solid #f0d4d7; }
.chat-policy-state strong,.chat-policy-state span { display:inline-flex;padding:.35rem .6rem;border-radius:999px;background:#f1f5f9;font-size:.76rem;font-weight:850; }
.chat-policy-state strong.is-accepted { background:#ecfdf3;color:var(--chat-success); }
.chat-policy-state strong.is-blocked { background:#fff1f2;color:var(--chat-danger); }
.chat-role-badge.is-restricted { background:#fff1f2;color:var(--chat-danger);border-color:#fecdd3; }
.public-chat__gate { min-height: 520px; }
.chat-access-gate { width:min(680px,calc(100% - 36px));margin:auto;padding:28px;border:1px solid #dbe3ec;border-radius:20px;background:#f8fafc;text-align:center;box-shadow:0 12px 30px rgba(15,23,42,.06); }
.chat-access-gate--blocked { border-color:#fecdd3;background:#fff7f7; }
.chat-access-gate__icon { width:52px;height:52px;display:grid;place-items:center;margin:0 auto 13px;border-radius:50%;background:#e0e7ff;color:var(--chat-primary);font-size:25px;font-weight:950; }
.chat-access-gate--blocked .chat-access-gate__icon { background:#ffe4e6;color:var(--chat-danger); }
.chat-access-gate h3 { margin:0;font-size:1.35rem; }
.chat-access-gate p { margin:.7rem auto 0;max-width:560px;color:var(--chat-muted);line-height:1.7; }
.chat-policy-consent { display:flex;align-items:flex-start;gap:.7rem;margin:20px 0 14px;padding:14px;border:1px solid #cbd5e1;border-radius:14px;background:#fff;text-align:left;font-weight:800;line-height:1.55;cursor:pointer; }
.chat-policy-consent input { width:20px;height:20px;flex:0 0 auto;margin-top:1px; }
.chat-access-gate .chat-button { margin-top:4px; }
.chat-access-gate__note { font-size:.85rem; }
.chat-restriction-detail { display:grid;gap:8px;margin:18px 0 4px;text-align:left; }
.chat-restriction-detail>div { display:grid;grid-template-columns:92px 1fr;gap:10px;padding:10px 12px;border:1px solid #fecdd3;border-radius:12px;background:#fff; }
.chat-restriction-detail dt { color:#9f1239;font-weight:900; }
.chat-restriction-detail dd { margin:0;white-space:pre-wrap;word-break:break-word; }
@media(max-width:620px){
  .public-chat__gate { min-height:calc(100dvh - 64px); }
  .chat-access-gate { width:calc(100% - 28px);padding:20px 16px; }
  .chat-restriction-detail>div { grid-template-columns:1fr;gap:3px; }
}


/* [PUBLIC CHAT MEMBER REPORT] 메시지 신고 단추·한글 신고창 */
.chat-message-report-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: .35rem;
}

.chat-message-report-button {
  min-height: 28px;
  padding: .3rem .62rem;
  border: 1px solid #d6dce6;
  border-radius: 999px;
  background: #fff;
  color: #7a3440;
  font-size: .76rem;
  font-weight: 800;
  cursor: pointer;
}

.chat-message-report-button:hover,
.chat-message-report-button:focus-visible {
  border-color: #bd2d3a;
  background: #fff4f5;
  outline: none;
}

.chat-message-report-button:disabled {
  cursor: default;
  opacity: .62;
}

.chat-report-dialog {
  width: min(520px, calc(100% - 28px));
  padding: 0;
  border: 0;
  border-radius: 20px;
  background: #fff;
  color: var(--chat-text);
  box-shadow: 0 28px 90px rgba(15, 23, 42, .28);
}

.chat-report-dialog::backdrop {
  background: rgba(15, 23, 42, .58);
  backdrop-filter: blur(4px);
}

.chat-report-dialog form {
  display: grid;
  gap: 16px;
  padding: 20px;
}

.chat-report-dialog header,
.chat-report-dialog footer {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.chat-report-dialog header h2 {
  margin: 0;
  font-size: 20px;
}

.chat-report-dialog header p {
  margin: 5px 0 0;
  color: var(--chat-muted);
  font-size: 13px;
  line-height: 1.55;
}

.chat-report-dialog header > button {
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--chat-line);
  border-radius: 10px;
  background: #fff;
  color: var(--chat-muted);
  font-size: 22px;
  cursor: pointer;
}

.chat-report-dialog label {
  display: grid;
  gap: 7px;
  font-size: 13px;
  font-weight: 800;
}

.chat-report-dialog select,
.chat-report-dialog textarea {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--chat-line);
  border-radius: 12px;
  background: #fff;
  color: var(--chat-text);
}

.chat-report-dialog textarea {
  resize: vertical;
  min-height: 104px;
}

.chat-report-dialog footer {
  justify-content: flex-end;
}

.chat-button--danger {
  border-color: var(--chat-danger) !important;
  background: var(--chat-danger) !important;
  color: #fff !important;
}

@media (max-width: 560px) {
  .chat-report-dialog form { padding: 16px; }
}
