/* ai-hub · 화면 스타일
   기준: 장식 없는 사무용 메신저. 그라데이션·네온·이모지 없음. */

:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #fafbfc;
  --border: #e2e5e9;
  --border-strong: #cfd5dc;
  --text: #15181d;
  --text-2: #565f6b;
  --text-3: #878f9a;
  --accent: #2563eb;
  --accent-soft: #edf2fe;
  --hover: #f1f3f6;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 12px 32px rgba(16, 24, 40, 0.08);
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #14161a;
  --surface: #1b1e24;
  --surface-2: #21252c;
  --border: #2b3038;
  --border-strong: #3b424c;
  --text: #e7eaee;
  --text-2: #a5adb8;
  --text-3: #79818d;
  --accent: #5b8def;
  --accent-soft: #1e2839;
  --hover: #242931;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 14px 34px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Apple SD Gothic Neo",
    "Noto Sans KR", "Malgun Gothic", system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button { font: inherit; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.app {
  display: grid;
  grid-template-columns: 272px minmax(0, 1fr);
  height: 100dvh;
  overflow: hidden;
}

/* ── 사이드바 ───────────────────────────────────────── */

.sidebar {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 56px;
  padding: 0 16px;
  flex: none;
}

.brand-mark {
  width: 27px;
  height: 27px;
  border-radius: 7px;
  background: var(--text);
  color: var(--surface);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.01em;
  display: grid;
  place-items: center;
  flex: none;
}

.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text strong { font-size: 13.5px; font-weight: 650; letter-spacing: -0.01em; }
.brand-text span { font-size: 11px; color: var(--text-3); }

.side-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 2px 8px 14px;
  scrollbar-width: thin;
}

.side-section { margin-top: 12px; }

.side-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 8px 6px;
  font-size: 10.5px;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-3);
}

.side-count { font-weight: 500; letter-spacing: 0; }

.room-list { display: flex; flex-direction: column; gap: 1px; }

.room-list button {
  display: flex;
  align-items: center;
  gap: 7px;
  width: 100%;
  height: 31px;
  padding: 0 8px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--text-2);
  font-size: 13px;
  text-align: left;
  cursor: pointer;
}

.room-list button:hover { background: var(--hover); color: var(--text); }

.room-list button.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.room-list .hash { color: var(--text-3); font-weight: 500; }
.room-list button.active .hash { color: var(--accent); }

.room-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.room-time {
  margin-left: auto;
  font-size: 10.5px;
  font-weight: 400;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}

.member-list { display: flex; flex-direction: column; gap: 1px; }

.member {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 5px 8px;
  border-radius: 7px;
}

.member:hover { background: var(--hover); }

.m-avatar {
  width: 24px;
  height: 24px;
  border-radius: 7px;
  background: var(--c, #6b7280);
  color: #fff;
  font-size: 10.5px;
  font-weight: 600;
  display: grid;
  place-items: center;
  flex: none;
}

.m-info { min-width: 0; flex: 1; }

.m-name {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12.5px;
  font-weight: 500;
  line-height: 1.3;
}

.m-role {
  font-size: 11px;
  color: var(--text-3);
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--border-strong);
  flex: none;
}

.status.on { background: #1f9d63; }

.side-foot {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px;
  border-top: 1px solid var(--border);
  flex: none;
}

.conn {
  display: flex;
  align-items: center;
  gap: 7px;
  flex: 1;
  height: 32px;
  padding: 0 9px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 11.5px;
  cursor: pointer;
  overflow: hidden;
  white-space: nowrap;
}

.conn:hover { border-color: var(--border-strong); color: var(--text); }

.conn-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--border-strong);
  flex: none;
}

.conn.on .conn-dot { background: #1f9d63; }
.conn.on { color: var(--text); }

.conn-label {
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── 채팅 ──────────────────────────────────────────── */

.chat {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  position: relative;
  background: var(--bg);
}

.chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 58px;
  padding: 0 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex: none;
}

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

.chat-title h1 {
  display: flex;
  align-items: baseline;
  gap: 5px;
  margin: 0;
  font-size: 14.5px;
  font-weight: 650;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.chat-title .hash { color: var(--text-3); font-weight: 400; }

.chat-title p {
  margin: 1px 0 0;
  font-size: 11.5px;
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-actions { display: flex; align-items: center; gap: 6px; flex: none; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 30px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text-2);
  font-size: 12.5px;
  cursor: pointer;
  white-space: nowrap;
}

.btn:hover { border-color: var(--border-strong); background: var(--surface-2); color: var(--text); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn.icon-only { width: 30px; padding: 0; }

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

.btn.primary:hover { filter: brightness(1.05); background: var(--accent); color: #fff; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--text-3);
  cursor: pointer;
  flex: none;
}

.icon-btn:hover { background: var(--hover); color: var(--text); }

/* 타임라인 */

.timeline {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 6px 0 18px;
  scrollbar-width: thin;
}

.day-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 20px 6px;
  font-size: 11px;
  color: var(--text-3);
}

.day-divider::before,
.day-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.msg {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) 26px;
  gap: 10px;
  padding: 3px 18px 3px 16px;
  position: relative;
}

.msg:hover { background: var(--hover); }
.msg:hover + .msg { box-shadow: inset 0 1px 0 var(--border); }

.msg-gutter {
  grid-column: 1;
  display: flex;
  justify-content: center;
  padding-top: 2px;
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: var(--c, #6b7280);
  color: #fff;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: -0.01em;
  display: grid;
  place-items: center;
  flex: none;
  user-select: none;
}

.hover-time {
  display: none;
  padding-top: 3px;
  font-size: 10px;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}

.msg.grouped .avatar { display: none; }
.msg.grouped .hover-time { display: block; opacity: 0; }
.msg.grouped:hover .hover-time { opacity: 1; }

.msg-body { grid-column: 2; min-width: 0; padding-bottom: 2px; }

.msg-head {
  display: flex;
  align-items: baseline;
  gap: 6px;
  min-height: 21px;
}

.msg.grouped .msg-head { display: none; }

.msg-name { font-size: 13px; font-weight: 650; color: var(--text); }

.msg-role { font-size: 10.5px; color: var(--text-3); }

.msg-time {
  margin-left: 2px;
  font-size: 10.5px;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}

.msg-text {
  font-size: 13.5px;
  line-height: 1.62;
  color: var(--text);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.msg-text:empty { display: none; }

.msg-copy {
  grid-column: 3;
  align-self: start;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  margin-top: 1px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text-3);
  cursor: pointer;
  opacity: 0;
}

.msg:hover .msg-copy { opacity: 1; }
.msg-copy:hover { color: var(--text); border-color: var(--border-strong); }

/* 첨부 카드 */

.attach-list {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  margin-top: 7px;
}

.attach {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  max-width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 12.5px;
  cursor: pointer;
  text-align: left;
}

.attach:hover { border-color: var(--border-strong); background: var(--surface-2); }
.attach > svg { flex: none; color: var(--text-3); }

.attach-name {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 340px;
}

.attach-size {
  font-size: 10.5px;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
  flex: none;
}

.attach-dl { opacity: 0; transition: opacity 0.1s; }
.attach:hover .attach-dl { opacity: 1; }

/* 빈 상태·오류 */

.state {
  max-width: 420px;
  margin: 64px auto;
  padding: 0 24px;
  text-align: center;
  color: var(--text-2);
}

.state h3 { margin: 0 0 6px; font-size: 13.5px; font-weight: 650; color: var(--text); }
.state p { margin: 0; font-size: 12.5px; line-height: 1.65; color: var(--text-3); }
.state code {
  display: inline-block;
  margin-top: 8px;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  font-size: 11.5px;
  color: var(--text-2);
}

/* ── 입력 ──────────────────────────────────────────── */

.composer {
  flex: none;
  padding: 8px 16px 12px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.composer-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 11.5px;
  color: var(--text-3);
}

.composer-meta label { font-size: 11.5px; color: var(--text-3); }

#sender {
  height: 26px;
  max-width: 190px;
  padding: 0 6px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 12px;
  cursor: pointer;
}

.kbd-hint { margin-left: auto; font-size: 10.5px; color: var(--text-3); }

.pending {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 6px;
}

.pending:empty { display: none; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 5px 3px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-2);
  font-size: 11.5px;
  color: var(--text-2);
}

.chip button {
  display: grid;
  place-items: center;
  width: 16px;
  height: 16px;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--text-3);
  cursor: pointer;
}

.chip button:hover { background: var(--hover); color: var(--text); }

.composer-row {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding: 5px 6px 5px 8px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background: var(--surface);
}

.composer-row:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

#input {
  flex: 1;
  min-width: 0;
  min-height: 26px;
  max-height: 168px;
  padding: 5px 2px;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 13.5px;
  line-height: 1.55;
  resize: none;
  outline: none;
  scrollbar-width: thin;
}

#input::placeholder { color: var(--text-3); }

.send-btn {
  height: 32px;
  padding: 0 14px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}

.send-btn:hover { filter: brightness(1.06); }
.send-btn:disabled { opacity: 0.5; cursor: default; filter: none; }

/* 드래그 안내 */

.drop-hint {
  position: absolute;
  inset: 66px 12px 96px;
  display: none;
  place-items: center;
  border: 1.5px dashed var(--accent);
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  pointer-events: none;
  z-index: 5;
}

.chat.dragging .drop-hint { display: grid; }

/* ── 설정 모달 ─────────────────────────────────────── */

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(14, 17, 21, 0.45);
}

.modal[hidden] { display: none; }

.modal-card {
  width: 100%;
  max-width: 540px;
  max-height: 90dvh;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
}

.modal-head h2 { margin: 0; font-size: 13.5px; font-weight: 650; }

.modal-body { padding: 15px 16px; display: grid; gap: 12px; }

.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.field label {
  display: block;
  margin-bottom: 5px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-2);
}

.field input {
  width: 100%;
  height: 34px;
  padding: 0 9px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 12.5px;
  outline: none;
}

.field input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.note {
  margin: 0;
  font-size: 11.5px;
  line-height: 1.65;
  color: var(--text-3);
}

.note-box {
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
}

.note-box strong { color: var(--text-2); font-weight: 600; }
.note-box em { font-style: normal; color: var(--text-2); }

.cfg-status {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  font-size: 11.5px;
  color: var(--text-2);
}

.cfg-status.ok { border-color: #b7ddc8; background: #eef8f1; color: #1c6b45; }
.cfg-status.err { border-color: #e8c4c0; background: #fdf1ef; color: #a3352b; }

[data-theme="dark"] .cfg-status.ok { border-color: #2f5a45; background: #16241d; color: #7fd3a7; }
[data-theme="dark"] .cfg-status.err { border-color: #5c3330; background: #241a19; color: #e79a92; }

.modal-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

.spacer { flex: 1; }

/* 토스트 */

.toast {
  position: fixed;
  left: 50%;
  bottom: 96px;
  z-index: 30;
  max-width: min(420px, calc(100vw - 32px));
  padding: 8px 14px;
  border-radius: 8px;
  background: #20242b;
  color: #f2f4f7;
  font-size: 12.5px;
  line-height: 1.5;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.22);
  opacity: 0;
  transform: translate(-50%, 6px);
  transition: opacity 0.16s, transform 0.16s;
  pointer-events: none;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* 스크롤바 */

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border: 3px solid transparent;
  border-radius: 6px;
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover { background: var(--text-3); background-clip: padding-box; }
::-webkit-scrollbar-track { background: transparent; }

/* ── 좁은 화면 ─────────────────────────────────────── */

@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); }

  .sidebar {
    flex-direction: row;
    align-items: stretch;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .brand { height: 52px; padding: 0 12px; border-right: 1px solid var(--border); flex: none; }
  .brand-text { display: none; }

  .side-scroll { display: flex; flex: 1; min-width: 0; overflow: hidden; padding: 0; }
  .side-section { margin: 0; }
  .side-title { display: none; }
  .members-section { display: none; }

  .rooms-section { display: flex; min-width: 0; flex: 1; }
  .room-list {
    flex-direction: row;
    gap: 2px;
    padding: 0 6px;
    min-width: 0;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .room-list::-webkit-scrollbar { display: none; }
  .room-list button {
    width: auto;
    height: 52px;
    padding: 0 11px;
    border-radius: 0;
    border-bottom: 2px solid transparent;
    white-space: nowrap;
  }
  .room-list button.active { background: transparent; border-bottom-color: var(--accent); }
  .room-time { display: none; }

  .side-foot { border-top: 0; padding: 0 8px 0 0; background: var(--surface); position: relative; z-index: 2; }
  .side-foot #themeBtn { display: none; }
  .conn { width: 30px; padding: 0; justify-content: center; }
  #connLabel { display: none; }

  .chat-head { height: 52px; padding: 0 14px; gap: 8px; }
  .chat-title p { display: none; }
  .chat-actions .btn span { display: none; }
  .chat-actions .btn { width: 30px; padding: 0; }

  .msg { grid-template-columns: 32px minmax(0, 1fr); padding-right: 14px; }
  .msg-copy { display: none; }
  .attach-name { max-width: 200px; }
  .composer { padding: 8px 12px 12px; }
  .kbd-hint { display: none; }
  .field-grid { grid-template-columns: 1fr; }
  .drop-hint { inset: 60px 10px 92px; }
  .toast { bottom: 84px; }
}
