:root {
  color-scheme: light;
  --ink: #172033;
  --muted: #667085;
  --subtle: #98a2b3;
  --primary: #2563eb;
  --focus: #075ab8;
  --soft-blue: #eaf2ff;
  --background: #f7f9fc;
  --surface: #ffffff;
  --line: #e4e9f1;
  --positive: #16835b;
  --warning: #a35e08;
  --danger: #c43d4b;
  --shadow: 0 18px 48px rgba(23, 32, 51, 0.12);
  font-family: Pretendard, "Noto Sans KR", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  min-width: 320px;
  min-height: 100dvh;
  margin: 0;
  background: #e9eef7;
  color: var(--ink);
  overscroll-behavior: none;
}
button, input, textarea { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
button:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 3px solid rgba(37, 99, 235, 0.26);
  outline-offset: 2px;
}
[hidden] { display: none !important; }

.app-shell {
  width: min(100%, 720px);
  min-height: 100dvh;
  margin: 0 auto;
  background: var(--background);
  box-shadow: 0 0 60px rgba(23, 32, 51, 0.14);
}

.brand-mark {
  display: block;
  width: 58px;
  height: 58px;
  object-fit: contain;
}
.brand-mark.small { width: 42px; height: 42px; }

.conversation-hub {
  min-height: 100dvh;
  padding: max(22px, env(safe-area-inset-top)) 18px max(24px, env(safe-area-inset-bottom));
  background: var(--background);
}
.hub-header {
  display: flex;
  min-height: 62px;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}
.hub-brand { display: flex; min-width: 0; align-items: center; gap: 11px; }
.hub-brand p { margin: 0 0 2px; color: var(--primary); font-size: 0.72rem; font-weight: 850; }
.hub-brand h1 { margin: 0; font-size: 1.42rem; letter-spacing: -0.035em; }
.hub-connect-button {
  min-height: 42px;
  padding: 0 14px;
  border: 1px solid #cfe0ff;
  border-radius: 13px;
  background: var(--soft-blue);
  color: var(--focus);
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 850;
}
.hub-intro { padding: 34px 2px 15px; }
.hub-intro strong { display: block; font-size: 1.1rem; letter-spacing: -0.025em; }
.hub-intro p { margin: 7px 0 0; color: var(--muted); font-size: 0.82rem; line-height: 1.55; }
.conversation-list { display: grid; margin: 0; padding: 0; gap: 10px; list-style: none; }
.conversation-card {
  display: grid;
  width: 100%;
  min-height: 94px;
  padding: 16px;
  grid-template-columns: 50px minmax(0, 1fr) 24px;
  align-items: center;
  gap: 13px;
  border: 1px solid var(--line);
  border-radius: 19px;
  background: var(--surface);
  box-shadow: 0 8px 28px rgba(23, 32, 51, 0.055);
  color: var(--ink);
  cursor: pointer;
  text-align: left;
}
.conversation-card:hover { border-color: #bfd3fb; transform: translateY(-1px); }
.conversation-avatar {
  display: grid;
  width: 50px;
  height: 50px;
  place-items: center;
  border-radius: 17px;
  background: linear-gradient(145deg, var(--primary), #173e91);
  color: #fff;
  font-size: 1.05rem;
  font-weight: 900;
}
.conversation-card-copy { display: block; min-width: 0; }
.conversation-card-copy strong,
.conversation-card-copy span,
.conversation-card-copy small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conversation-card-copy strong { font-size: 0.98rem; letter-spacing: -0.02em; }
.conversation-card-copy span { margin-top: 5px; color: var(--muted); font-size: 0.78rem; }
.conversation-card-copy small { margin-top: 5px; color: var(--positive); font-size: 0.69rem; font-weight: 800; }
.conversation-arrow { color: var(--subtle); font-size: 1.7rem; line-height: 1; }
.conversation-list-empty {
  padding: 58px 24px;
  border: 1px dashed #cbd5e4;
  border-radius: 19px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.65;
  text-align: center;
}
.hub-security-note {
  display: flex;
  margin-top: 20px;
  padding: 14px 15px;
  align-items: flex-start;
  gap: 9px;
  border-radius: 14px;
  background: #edf7f3;
  color: #23644d;
  font-size: 0.76rem;
  line-height: 1.5;
}
.hub-security-note span { font-weight: 900; }
.hub-security-note p { margin: 0; }

.onboarding-screen {
  min-height: 100dvh;
  padding: max(32px, env(safe-area-inset-top)) 22px max(32px, env(safe-area-inset-bottom));
}
.onboarding-header { padding: 10px 4px 0; }
.brand-name { margin: 14px 0 30px; color: var(--primary); font-size: 0.86rem; font-weight: 800; }
.onboarding-header h1 { margin: 0 0 14px; font-size: clamp(1.85rem, 8vw, 2.65rem); letter-spacing: -0.045em; }
.onboarding-copy { margin: 0; color: var(--muted); line-height: 1.65; }

.security-note {
  display: flex;
  gap: 12px;
  margin: 26px 0 14px;
  padding: 16px;
  border: 1px solid #cfe0ff;
  border-radius: 16px;
  background: var(--soft-blue);
}
.security-icon {
  display: grid;
  width: 28px;
  height: 28px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-weight: 900;
}
.security-note strong { font-size: 0.93rem; }
.security-note p { margin: 5px 0 0; color: #49627e; font-size: 0.82rem; line-height: 1.55; }

.consent-card {
  margin: 0 0 14px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--surface);
}
.consent-eyebrow { margin: 0 0 6px; color: var(--primary); font-size: 0.72rem; font-weight: 900; }
.consent-card h2 { margin: 0; font-size: 1.08rem; letter-spacing: -0.025em; }
.consent-card ul { display: grid; margin: 17px 0; padding: 0; gap: 13px; list-style: none; }
.consent-card li { display: grid; gap: 3px; }
.consent-card li strong { font-size: 0.84rem; }
.consent-card li span { color: var(--muted); font-size: 0.77rem; line-height: 1.5; }
.consent-before-note {
  margin: 0 0 10px;
  padding: 10px 12px;
  border: 1px solid #c7dcf5;
  border-radius: 12px;
  background: #f5f9ff;
  color: #294c78;
  font-size: 0.76rem;
  font-weight: 800;
  line-height: 1.5;
}
.consent-check {
  display: flex;
  min-height: 52px;
  padding: 12px;
  align-items: flex-start;
  gap: 10px;
  border-radius: 14px;
  background: var(--soft-blue);
  color: #294c78;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 800;
  line-height: 1.5;
}
.consent-check + .consent-check { margin-top: 8px; }
.consent-check span { display: grid; gap: 2px; }
.consent-check strong { font-size: 0.81rem; }
.consent-check small { color: #49627e; font-size: 0.72rem; font-weight: 600; }
.consent-check input { width: 20px; height: 20px; margin: 1px 0 0; flex: 0 0 auto; accent-color: var(--primary); }

.enrollment-card {
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.step-row { display: flex; gap: 12px; align-items: flex-start; }
.step-row strong { display: block; margin-top: 2px; font-size: 0.96rem; }
.step-row p { margin: 5px 0 0; color: var(--muted); font-size: 0.8rem; }
.step-number {
  display: grid;
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 10px;
  background: var(--soft-blue);
  color: var(--focus);
  font-size: 0.8rem;
  font-weight: 900;
}

.primary-button, .secondary-button, .danger-button, .text-button {
  width: 100%;
  min-height: 48px;
  border: 0;
  border-radius: 14px;
  cursor: pointer;
  font-weight: 800;
}
.primary-button { margin-top: 16px; background: var(--primary); color: #fff; }
.primary-button:hover:not(:disabled) { background: var(--focus); }
.primary-button:disabled, .secondary-button:disabled, .danger-button:disabled { cursor: not-allowed; opacity: 0.45; }
.field-label { display: block; margin: 16px 0 7px; color: var(--muted); font-size: 0.82rem; font-weight: 700; }
.entry-input {
  width: 100%;
  height: 52px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--background);
  color: var(--ink);
  font-size: 1rem;
  font-weight: 800;
  text-align: center;
}
.entry-input.code { font-size: 1.16rem; letter-spacing: 0.34em; }
.conversation-entry {
  margin-top: 14px;
  padding: 2px 14px 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--background);
}
.conversation-entry .entry-input { background: var(--surface); }
.entry-note { margin: 10px 2px 0; color: var(--muted); font-size: 0.74rem; line-height: 1.5; }
.connection-facts, .settings-facts { margin: 22px 0 0; }
.connection-facts div, .settings-facts div {
  display: grid;
  grid-template-columns: 110px minmax(0, 1fr);
  gap: 12px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
}
.connection-facts dt, .settings-facts dt { color: var(--muted); font-size: 0.8rem; }
.connection-facts dd, .settings-facts dd { margin: 0; overflow-wrap: anywhere; font-size: 0.8rem; font-weight: 750; text-align: right; }
.replace-note { margin: 18px 6px 0; color: var(--subtle); font-size: 0.77rem; line-height: 1.55; text-align: center; }

.chat-screen {
  display: grid;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  max-height: 100dvh;
  overflow: hidden;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
}
.chat-header {
  display: flex;
  min-height: 72px;
  padding: max(12px, env(safe-area-inset-top)) 16px 11px;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
}
.chat-header .list-button { margin-right: 10px; }
.chat-header-actions { display: flex; gap: 6px; }
.chat-header-actions .icon-button { min-width: 44px; padding: 0 9px; }
.chat-header-actions .invite-button { border-color: #cfe0ff; background: var(--soft-blue); color: var(--focus); }
.chat-title-group { display: flex; gap: 11px; align-items: center; }
.chat-title-group { min-width: 0; flex: 1; }
.chat-title-group > div { min-width: 0; }
.chat-title-group h1 { margin: 0; font-size: 1.05rem; letter-spacing: -0.025em; }
.chat-title-group h1 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-title-group p { display: flex; margin: 4px 0 0; align-items: center; color: var(--muted); font-size: 0.75rem; }
.connection-dot { width: 7px; height: 7px; margin-right: 6px; border-radius: 50%; background: var(--warning); }
.connection-dot.online { background: var(--positive); }
.connection-dot.offline { background: var(--danger); }
.icon-button, .close-button {
  min-width: 48px;
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 800;
}

.access-banner {
  display: flex;
  min-height: 40px;
  padding: 9px 16px;
  align-items: center;
  gap: 8px;
  background: #edf7f3;
  color: #23644d;
  font-size: 0.76rem;
}
.access-banner p { margin: 0; }
.access-banner.closed { background: #fff5e9; color: #85510f; }
.access-banner.expired { background: #fff0f2; color: #9c2f3c; }

.message-region {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-behavior: smooth;
  background:
    radial-gradient(circle at 20% 12%, rgba(37, 99, 235, 0.055), transparent 18rem),
    var(--background);
}
.loading-state {
  display: flex;
  min-height: 56vh;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 0.84rem;
}
.spinner {
  width: 26px;
  height: 26px;
  border: 3px solid #d9e4f7;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}
.spinner.light { border-color: rgba(255, 255, 255, 0.24); border-top-color: #fff; }
@keyframes spin { to { transform: rotate(360deg); } }

.message-list { margin: 0; padding: 22px 16px 28px; list-style: none; }
.empty-conversation { padding: 22vh 26px 0; color: var(--muted); font-size: 0.88rem; line-height: 1.6; text-align: center; }
.date-divider { display: flex; margin: 17px 0; align-items: center; gap: 10px; color: var(--subtle); font-size: 0.7rem; }
.date-divider::before, .date-divider::after { height: 1px; flex: 1; background: var(--line); content: ""; }
.message-row { display: flex; margin: 9px 0; flex-direction: column; align-items: flex-start; }
.message-row.mine { align-items: flex-end; }
.message-row.system { align-items: center; }
.message-sender-name { margin: 0 0 4px 5px; color: var(--muted); font-size: 0.7rem; font-weight: 700; }
.message-bubble {
  max-width: min(82%, 420px);
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 17px 17px 17px 5px;
  background: var(--surface);
  box-shadow: 0 4px 16px rgba(23, 32, 51, 0.045);
}
.mine .message-bubble { border-color: #d8e5ff; border-radius: 17px 17px 5px 17px; background: var(--soft-blue); }
.system .message-bubble { border: 0; border-radius: 999px; background: #edf0f5; color: var(--muted); text-align: center; }
.message-text { margin: 0; overflow-wrap: anywhere; font-size: 0.92rem; line-height: 1.55; white-space: pre-wrap; }
.message-time { margin-top: 4px; color: var(--subtle); font-size: 0.66rem; }

.attachment-card {
  display: flex;
  width: min(270px, 70vw);
  min-height: 66px;
  margin: 0 0 7px;
  padding: 9px;
  align-items: center;
  gap: 10px;
  border: 1px solid #dce5f4;
  border-radius: 13px;
  background: rgba(255, 255, 255, 0.88);
  color: var(--ink);
  cursor: pointer;
  text-align: left;
}
.attachment-card:last-child { margin-bottom: 0; }
.attachment-card:hover { border-color: #abc6fa; background: #fff; }
.attachment-icon {
  display: grid;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 12px;
  background: var(--soft-blue);
  color: var(--focus);
  font-size: 0.72rem;
  font-weight: 900;
}
.attachment-copy { min-width: 0; flex: 1; }
.attachment-copy strong { display: block; font-size: 0.8rem; }
.attachment-copy span { display: block; margin-top: 4px; color: var(--muted); font-size: 0.67rem; overflow-wrap: anywhere; }
.attachment-open { color: var(--primary); font-size: 0.72rem; font-weight: 900; }
.message-bubble .message-text:not(:first-child) { margin-top: 7px; padding-top: 8px; border-top: 1px solid rgba(102, 112, 133, 0.14); }

.composer {
  display: grid;
  padding: 10px 12px max(10px, env(safe-area-inset-bottom));
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 9px;
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.98);
}
.selected-media {
  display: flex;
  min-width: 0;
  min-height: 64px;
  padding: 8px;
  grid-column: 1 / -1;
  align-items: center;
  gap: 10px;
  border: 1px solid #cfe0ff;
  border-radius: 14px;
  background: #f5f9ff;
}
.selected-media img, .selected-media-icon {
  width: 48px;
  height: 48px;
  flex: 0 0 auto;
  border-radius: 11px;
  object-fit: cover;
}
.selected-media-icon { display: grid; place-items: center; background: #dbe9ff; color: var(--focus); font-size: 0.7rem; font-weight: 900; }
.selected-media-copy { min-width: 0; flex: 1; }
.selected-media-copy strong, .selected-media-copy small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.selected-media-copy strong { font-size: 0.8rem; }
.selected-media-copy small { margin-top: 4px; color: var(--muted); font-size: 0.7rem; }
.selected-media-remove { min-height: 36px; padding: 0 10px; border: 0; border-radius: 10px; background: #fff0f2; color: var(--danger); cursor: pointer; font-size: 0.72rem; font-weight: 850; }
.attach-button {
  width: 46px;
  height: 46px;
  padding: 0;
  align-self: end;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: var(--surface);
  color: var(--primary);
  cursor: pointer;
  font-size: 1.55rem;
  line-height: 1;
}
.attach-button:disabled { cursor: not-allowed; opacity: 0.45; }
.composer textarea {
  width: 100%;
  max-height: 120px;
  min-height: 46px;
  padding: 12px 14px;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--background);
  color: var(--ink);
  line-height: 1.4;
}
.composer textarea:disabled { opacity: 0.65; }
.send-button {
  min-width: 64px;
  height: 46px;
  padding: 0 14px;
  align-self: end;
  border: 0;
  border-radius: 15px;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 900;
}
.send-button:disabled { cursor: not-allowed; opacity: 0.45; }

dialog { padding: 0; border: 0; }
dialog::backdrop { background: rgba(12, 20, 36, 0.55); backdrop-filter: blur(2px); }
.sheet-dialog {
  width: min(100% - 24px, 520px);
  max-height: min(86dvh, 760px);
  margin: auto auto 0;
  padding: 10px 20px max(24px, env(safe-area-inset-bottom));
  overflow-y: auto;
  border-radius: 24px 24px 0 0;
  background: var(--surface);
  color: var(--ink);
}
.dialog-handle { width: 42px; height: 4px; margin: 0 auto 18px; border-radius: 4px; background: #d6dce7; }
.dialog-header, .viewer-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.dialog-header h2, .viewer-header h2 { margin: 2px 0 0; font-size: 1.18rem; }
.dialog-eyebrow { margin: 0; color: var(--primary); font-size: 0.69rem; font-weight: 900; letter-spacing: 0.06em; text-transform: uppercase; }
.settings-facts { margin-bottom: 20px; }
.secondary-button { margin-top: 9px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); }
.secondary-button:hover:not(:disabled) { background: var(--background); }
.dialog-help { margin: 12px 2px 20px; color: var(--muted); font-size: 0.75rem; line-height: 1.55; }
.invite-input {
  width: 100%;
  height: 50px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--background);
  color: var(--ink);
}
.invite-result { margin-top: 18px; padding: 18px; border-radius: 17px; background: var(--soft-blue); text-align: center; }
.invite-result p { margin: 0; color: #49627e; font-size: 0.76rem; line-height: 1.55; }
.invite-result > strong { display: block; margin: 13px 0 9px; color: var(--focus); font-size: 2rem; letter-spacing: 0.2em; }
.danger-button { margin-top: 6px; background: #fff0f2; color: var(--danger); }
.text-button { margin-top: 8px; background: transparent; color: var(--muted); font-size: 0.77rem; }

.viewer-dialog {
  width: min(100%, 720px);
  max-width: none;
  height: 100dvh;
  max-height: none;
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 16px max(18px, env(safe-area-inset-bottom));
  background: #101827;
  color: #fff;
}
.viewer-header { min-height: 58px; }
.viewer-header .dialog-eyebrow { color: #a9c7ff; }
.close-button.inverse { border-color: rgba(255,255,255,0.18); background: rgba(255,255,255,0.08); color: #fff; }
.viewer-body { display: grid; height: calc(100dvh - 142px); place-items: center; }
.viewer-body img, .viewer-body video { max-width: 100%; max-height: 100%; border-radius: 12px; background: #05070b; }
.viewer-loading { display: flex; flex-direction: column; align-items: center; color: #d8e2f2; font-size: 0.83rem; }
.viewer-error { max-width: 320px; color: #ffd3d7; line-height: 1.6; text-align: center; }
.viewer-meta { margin: 8px 0 0; color: #aebbd0; font-size: 0.72rem; text-align: center; }

.toast {
  position: fixed;
  z-index: 20;
  right: 16px;
  bottom: max(18px, env(safe-area-inset-bottom));
  left: 16px;
  width: min(calc(100% - 32px), 520px);
  margin: 0 auto;
  padding: 13px 16px;
  border-radius: 14px;
  background: #172033;
  box-shadow: var(--shadow);
  color: #fff;
  font-size: 0.82rem;
  line-height: 1.45;
}
.toast p { margin: 0; }
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (min-width: 721px) {
  .app-shell { min-height: min(100dvh, 920px); }
  .chat-screen { height: min(100dvh, 920px); max-height: 920px; }
  .onboarding-screen { min-height: min(100dvh, 920px); padding-right: 76px; padding-left: 76px; }
  .sheet-dialog { margin-bottom: 4vh; border-radius: 24px; }
  .viewer-dialog { height: min(100dvh, 920px); margin: auto; border-radius: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
}
