/* ===== Chat Shell ===== */
.chat {
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  height: 100dvh;
  background: var(--bg);
  overflow: hidden;
}

/* ===== Presence Bar ===== */
.presence-bar {
  display: flex;
  gap: 8px;
  padding: 10px 14px 14px;
  overflow-x: auto;
  scrollbar-width: thin;
  background: transparent;
}
.presence-chip {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius-full);
  background: var(--surface-container);
  font-size: .85rem;
  font-weight: 700;
  color: #1a1a1a;
  white-space: nowrap;
}
.badge-teacher {
  background: var(--bubble-me);
  color: var(--bubble-me-text);
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-size: .68rem;
  font-weight: 700;
  margin-left: 6px;
  letter-spacing: 0.02em;
}

/* ===== Messages ===== */
.messages {
  padding: 8px 16px 20px;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  margin-top: 14px;
}
.row.me { justify-content: flex-end; margin-right: 0; }
.row:not(.me) { margin-left: 0; }
.row.grouped { margin-top: 3px; }

.avatar-lg {
  min-width: 58px;
  max-width: 72px;
  height: auto;
  min-height: 32px;
  border-radius: 14px;
  background: #e1e2e4;
  color: #1a1a1a;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-family: var(--font-body);
  font-size: .75rem;
  line-height: 1.2;
  text-align: center;
  flex-shrink: 0;
  padding: 6px 10px;
  word-break: keep-all;
  box-shadow: 0 1px 2px rgba(0,0,0,.08);
}
.row.me .avatar-lg { display: none; }
.row.grouped .avatar-lg { visibility: hidden; }

.col {
  display: flex;
  flex-direction: column;
  max-width: min(62%, 520px);
}
.nick {
  font-size: .78rem;
  color: var(--text-dim);
  margin: 0 6px 4px;
  font-weight: 600;
}
.row.me .col { align-items: flex-end; }

.bubble {
  background: var(--bubble-other);
  color: var(--text);
  padding: 12px 16px;
  border-radius: var(--radius-lg);
  font-size: .95rem;
  line-height: 1.45;
  word-break: break-word;
  white-space: pre-wrap;
  position: relative;
}
.row.me .bubble {
  background: var(--bubble-me);
  color: var(--bubble-me-text);
  border-top-right-radius: 4px;
}
.row:not(.me) .bubble {
  border-top-left-radius: 4px;
}
.bubble.image { padding: 0; overflow: hidden; border-radius: var(--radius-lg); }
.bubble.image img {
  display: block;
  max-width: 260px;
  max-height: 260px;
  object-fit: cover;
  cursor: zoom-in;
}
.bubble.file {
  display: flex;
  gap: 12px;
  align-items: center;
  min-width: 200px;
}
.bubble.file a { font-weight: 600; text-decoration: none; color: inherit; }
.meta {
  font-size: .68rem;
  color: var(--text-dim);
  margin: 3px 8px 0;
  font-variant-numeric: tabular-nums;
}
.delete-btn {
  position: absolute;
  top: -8px;
  right: -8px;
  background: var(--danger);
  color: white;
  border: 0;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  font-size: .8rem;
  display: none;
  box-shadow: var(--shadow-ambient);
}
.bubble:hover .delete-btn { display: inline-grid; place-items: center; }

.date-divider { text-align: center; margin: 18px 0 8px; }
.date-divider span {
  background: var(--surface-container);
  color: var(--text-dim);
  padding: 6px 14px;
  border-radius: var(--radius-full);
  font-size: .75rem;
  font-weight: 600;
}

/* ===== Composer ===== */
.composer {
  position: sticky;
  bottom: 0;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 12px 14px 16px;
  background: rgba(248, 249, 251, 0.85);
  backdrop-filter: blur(18px) saturate(1.1);
  -webkit-backdrop-filter: blur(18px) saturate(1.1);
}
html[data-theme="dark"] .composer {
  background: rgba(21, 23, 26, 0.85);
}
.composer .icon-btn {
  width: 46px;
  height: 46px;
  background: var(--surface-container);
  font-size: 1.3rem;
  flex-shrink: 0;
}
.composer .icon-btn:hover { background: var(--surface-high); }
.composer textarea {
  flex: 1;
  resize: none;
  max-height: 7rem;
  padding: 13px 18px;
  border: 0;
  border-radius: var(--radius-full);
  background: var(--surface-container);
  color: var(--text);
  font-family: inherit;
  font-size: .95rem;
  line-height: 1.4;
}
.composer textarea:focus {
  outline: 0;
  background: var(--surface-high);
  box-shadow: 0 0 0 2px rgba(105, 95, 0, 0.18);
}
.send-btn {
  background: #ffeb33;
  color: #201c00;
  border: 0;
  border-radius: 50%;
  width: 46px;
  height: 46px;
  font-weight: 700;
  font-family: var(--font-headline);
  flex-shrink: 0;
  transition: filter .15s, transform .08s;
}
.send-btn:hover { filter: brightness(0.96); }
.send-btn:active { transform: scale(0.96); }

/* ===== Drop Overlay & Lightbox ===== */
.drop-overlay {
  position: fixed;
  inset: 16px;
  background: rgba(255, 235, 51, 0.22);
  display: grid;
  place-items: center;
  font-size: 1.3rem;
  font-weight: 700;
  font-family: var(--font-headline);
  color: var(--bubble-me-text);
  pointer-events: none;
  z-index: 50;
  border-radius: var(--radius-xl);
  outline: 3px dashed var(--primary);
  outline-offset: -6px;
  backdrop-filter: blur(2px);
}
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.88);
  display: grid;
  place-items: center;
  z-index: 100;
  cursor: zoom-out;
  backdrop-filter: blur(8px);
}
.lightbox img {
  max-width: 95vw;
  max-height: 95vh;
  border-radius: var(--radius-md);
}

@media (max-width: 640px) {
  .col { max-width: 82%; }
  .app-header h1 { font-size: .98rem; }
  .messages { padding: 6px 12px 16px; }
}

/* ===== Chat Header with cohort info ===== */
.chat-header {
  height: auto;
  min-height: 62px;
  padding: 10px 14px;
  gap: 10px;
}
.chat-title {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.chat-title h1 {
  margin: 0;
  font-size: clamp(1rem, 2.4vw, 1.15rem);
  font-family: var(--font-headline);
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-sub {
  font-size: .75rem;
  color: var(--text-dim);
  display: flex;
  gap: 6px;
  align-items: center;
}
.chat-sub .dot { color: var(--text-dim); }

.bubble .msg-link {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
  word-break: break-all;
}
.row.me .bubble .msg-link { color: #201c00; }

/* 날씨/계절/시간대 배경 - 공통 전환 */
.chat {
  transition: background 2s ease;
  position: relative;
}
/* 날씨 오버레이 */
.chat[data-weather="rain"]::before,
.chat[data-weather="snow"]::before,
.chat[data-weather="fog"]::before,
.chat[data-weather="thunder"]::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}
.chat[data-weather="rain"]::before {
  background:
    repeating-linear-gradient(100deg, rgba(255,255,255,0.08) 0 2px, transparent 2px 14px);
  mix-blend-mode: overlay;
}
.chat[data-weather="snow"]::before {
  background:
    radial-gradient(circle at 20% 30%, rgba(255,255,255,.55) 1.5px, transparent 2px) 0 0/60px 60px,
    radial-gradient(circle at 80% 70%, rgba(255,255,255,.45) 1px, transparent 2px) 0 0/40px 40px;
  mix-blend-mode: screen;
}
.chat[data-weather="fog"]::before {
  background: linear-gradient(180deg, rgba(255,255,255,.22), rgba(255,255,255,0));
}
.chat[data-weather="thunder"]::before {
  background: linear-gradient(180deg, rgba(0,0,0,.18), rgba(0,0,0,0));
}
.chat > * { position: relative; z-index: 1; }

.copy-btn {
  position: absolute;
  top: -8px;
  right: -8px;
  background: var(--surface-lowest);
  color: var(--text);
  border: 0;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: none;
  place-items: center;
  box-shadow: var(--shadow-ambient);
  cursor: pointer;
}
.bubble:hover .copy-btn { display: grid; }
.copy-btn.copied { background: var(--accent); color: #201c00; display: grid; }
.copy-btn svg { display: block; }
