:root {
  --navy: #1f3a5f;
  --navy-2: #2b4c7a;
  --accent: #2f7d6d;
  --bg: #f5f6f8;
  --panel: #ffffff;
  --line: #e2e5ea;
  --text: #1d2330;
  --muted: #6b7484;
  --user: #e8f0fb;
  --danger: #c0392b;
  --radius: 12px;
  font-family: 'Pretendard', 'Malgun Gothic', 'Apple SD Gothic Neo', sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
button, input, textarea { font: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.err { color: var(--danger); min-height: 1.2em; }
.row { display: flex; align-items: center; gap: 8px; }
.between { justify-content: space-between; }
.grow { flex: 1; }

/* 버튼 */
.btn { border: 1px solid var(--line); background: #fff; color: var(--text); border-radius: 8px;
  padding: 8px 14px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 4px; }
.btn:hover { background: #f0f2f5; }
.btn.primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn.primary:hover { background: var(--navy-2); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; color: #c9d4e5; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.icon { border: 0; background: transparent; font-size: 20px; cursor: pointer; padding: 4px 8px; color: inherit; }

/* 로그인 */
.login { min-height: 100%; display: grid; place-items: center; padding: 20px; background: var(--navy); }
.login-card { background: #fff; padding: 32px; border-radius: 16px; width: min(360px, 100%);
  display: flex; flex-direction: column; gap: 12px; }
.login-card h1 { margin: 0; font-size: 22px; color: var(--navy); }
.login-card input { padding: 12px; border: 1px solid var(--line); border-radius: 8px; }

/* 레이아웃 */
.app { display: grid; grid-template-columns: 260px 1fr auto; height: 100vh; height: 100dvh; }
.side { background: var(--navy); color: #fff; display: flex; flex-direction: column; min-height: 0; }
.side-head { padding: 16px; display: flex; justify-content: space-between; align-items: center; font-size: 17px; }
.dept-list { display: flex; flex-direction: column; gap: 4px; padding: 0 10px; }
.dept-btn { text-align: left; background: transparent; border: 0; color: #dfe7f3; padding: 10px 12px;
  border-radius: 8px; cursor: pointer; font-size: 15px; }
.dept-btn:hover { background: rgba(255,255,255,.08); }
.dept-btn.active { background: #fff; color: var(--navy); font-weight: 700; }
.side-sec { padding: 16px 10px 0; flex: 1; min-height: 0; display: flex; flex-direction: column; }
.side-sec .btn.small { background: rgba(255,255,255,.12); color: #fff; border-color: transparent; }
.label { font-size: 12px; color: #a9b8cf; letter-spacing: .05em; padding-left: 4px; }
.chat-list { list-style: none; margin: 8px 0 0; padding: 0; overflow-y: auto; flex: 1; }
.chat-list li { display: flex; align-items: center; border-radius: 8px; }
.chat-list li:hover { background: rgba(255,255,255,.08); }
.chat-list li.active { background: rgba(255,255,255,.16); }
.chat-list .chat-title { flex: 1; padding: 8px 10px; cursor: pointer; color: #e8eef7; font-size: 14px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; background: none; border: 0; text-align: left; }
.chat-list .del { visibility: hidden; color: #a9b8cf; font-size: 14px; }
.chat-list li:hover .del { visibility: visible; }
.side-foot { margin: 10px; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.top { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: #fff; }
.top-title { flex: 1; min-width: 0; }
.dept-name { font-weight: 700; font-size: 17px; color: var(--navy); }
.chips { display: flex; gap: 4px; overflow-x: auto; margin-top: 4px; scrollbar-width: none; }
.chip { font-size: 11.5px; padding: 2px 8px; border-radius: 99px; background: #eef1f6; color: #4a5568; white-space: nowrap; }
.chip.working { background: #dff3ee; color: var(--accent); font-weight: 700; }

.messages { flex: 1; overflow-y: auto; padding: 20px 16px 8px; display: flex; flex-direction: column; gap: 14px; }
.empty { margin: auto; text-align: center; color: var(--muted); max-width: 460px; line-height: 1.7; }
.empty h2 { color: var(--navy); margin: 0 0 8px; }
.examples { display: flex; flex-direction: column; gap: 6px; margin-top: 14px; }
.examples button { border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 10px 12px;
  text-align: left; cursor: pointer; color: var(--text); }
.examples button:hover { border-color: var(--navy); }

.msg { max-width: 820px; width: 100%; align-self: center; }
.msg.user .bubble { background: var(--user); margin-left: auto; max-width: 85%; width: fit-content; white-space: pre-wrap; }
.bubble { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; line-height: 1.65; overflow-wrap: anywhere; }
.msg.user .bubble { border-color: transparent; }
.who { font-size: 12px; color: var(--muted); margin: 0 4px 4px; }
.bubble h1, .bubble h2, .bubble h3 { margin: 14px 0 6px; line-height: 1.35; color: var(--navy); }
.bubble h1 { font-size: 19px; } .bubble h2 { font-size: 17px; } .bubble h3 { font-size: 15.5px; }
.bubble p { margin: 6px 0; }
.bubble ul, .bubble ol { margin: 6px 0; padding-left: 22px; }
.bubble table { border-collapse: collapse; margin: 8px 0; font-size: 14px; display: block; overflow-x: auto; }
.bubble th, .bubble td { border: 1px solid var(--line); padding: 6px 8px; vertical-align: top; }
.bubble th { background: #f3f5f8; }
.bubble code { background: #f1f3f6; padding: 1px 5px; border-radius: 4px; font-size: 13px; }
.bubble pre { background: #f1f3f6; padding: 10px; border-radius: 8px; overflow-x: auto; }
.bubble pre code { background: none; padding: 0; }
.bubble blockquote { margin: 6px 0; padding-left: 10px; border-left: 3px solid var(--line); color: var(--muted); }
.bubble a { color: var(--navy-2); }
.bubble .file-link { background: #eef5f3; color: var(--accent); border: 1px solid #cfe6df; border-radius: 6px;
  padding: 1px 6px; cursor: pointer; font-size: 13.5px; }
.bubble.error { border-color: #f0c6c0; background: #fdf3f2; color: #8a2c22; white-space: pre-wrap; }

.activity { margin: 0 0 6px; font-size: 13px; }
.activity summary { cursor: pointer; color: var(--muted); padding: 2px 4px; }
.activity ul { list-style: none; padding: 6px 0 0 6px; margin: 0; display: flex; flex-direction: column; gap: 3px; }
.act-member { color: var(--accent); font-weight: 600; }
.act-tool { color: var(--muted); padding-left: 14px; }
.live { display: flex; flex-direction: column; gap: 4px; padding: 10px 14px; background: #fff; border: 1px dashed #c8d3e2;
  border-radius: var(--radius); font-size: 13.5px; }
.live .now { color: var(--navy); font-weight: 600; }
.dots::after { content: ''; animation: dots 1.4s steps(4) infinite; }
@keyframes dots { 0% { content: ''; } 25% { content: '.'; } 50% { content: '..'; } 75% { content: '...'; } }

.composer { display: flex; gap: 8px; padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: #fff; align-items: flex-end; }
.composer textarea { flex: 1; resize: none; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
  max-height: 180px; line-height: 1.5; font-size: 15px; }
.composer textarea:focus { outline: 2px solid #b8c9e2; border-color: transparent; }

/* 자료 패널 */
.files { width: 340px; background: #fff; border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.files.collapsed { display: none; }
.files-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.tabs { display: flex; gap: 2px; }
.tab { border: 0; background: transparent; padding: 8px 10px; border-radius: 8px; cursor: pointer; color: var(--muted); }
.tab.active { background: #eef1f6; color: var(--navy); font-weight: 700; }
.file-pane { padding: 12px; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 8px; }
.upload { border: 2px dashed #c8d3e2; border-radius: 10px; padding: 14px; text-align: center; cursor: pointer; color: var(--navy-2); font-size: 14px; }
.upload.drag { background: #eef5ff; border-color: var(--navy-2); }
.file-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.file-list li { display: flex; align-items: center; gap: 6px; padding: 8px; border-radius: 8px; border: 1px solid var(--line); }
.file-list .fname { flex: 1; min-width: 0; cursor: pointer; background: none; border: 0; text-align: left; padding: 0; color: var(--text); }
.file-list .fname span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.file-list .fname small { color: var(--muted); font-size: 12px; }
.file-list .act { font-size: 15px; padding: 2px 6px; }
.desc-text { width: 100%; min-height: 380px; flex: 1; border: 1px solid var(--line); border-radius: 8px; padding: 10px; font-size: 14px; line-height: 1.6; }

/* 미리보기 */
.viewer { position: fixed; inset: 0; background: rgba(15, 22, 35, .75); display: flex; flex-direction: column; z-index: 50; }
.viewer-bar { display: flex; align-items: center; gap: 6px; padding: 8px 12px; background: #fff; }
.viewer-bar span:first-child { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer iframe { flex: 1; border: 0; background: #fff; }

.only-mobile { display: none; }

@media (max-width: 1100px) {
  .files { position: fixed; right: 0; top: 0; bottom: 0; z-index: 30; box-shadow: -8px 0 24px rgba(0,0,0,.12); width: min(380px, 92vw); }
}
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .only-mobile { display: inline-block; }
  .side { position: fixed; left: 0; top: 0; bottom: 0; width: min(290px, 85vw); z-index: 40; transform: translateX(-100%);
    transition: transform .2s; box-shadow: 8px 0 24px rgba(0,0,0,.2); }
  .side.open { transform: none; }
  .messages { padding: 14px 10px 8px; }
  .msg.user .bubble { max-width: 92%; }
  .composer { padding-left: 10px; padding-right: 10px; }
  .composer textarea { font-size: 16px; }
}
