:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --side: #14161c;
  --side-2: #1e2129;
  --side-text: #c9cdd6;
  --text: #1a1d29;
  --muted: #5d6475;
  --line: #e4e6ec;
  --accent: #e8590c;
  --accent-soft: #fff1e8;
  --ok: #15803d; --ok-soft: #ecf8f0;
  --warn: #a16207; --warn-soft: #fef7e6;
  --bad: #b42318; --bad-soft: #fdeceb;
  --code: #f2f3f6;
  --radius: 12px;
  --font: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", "맑은 고딕", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font-family: var(--font); background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.6; word-break: keep-all; overflow-wrap: anywhere; }
button { font-family: inherit; font-size: inherit; cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .5; }
input, textarea, select { font-family: inherit; font-size: inherit; }
.hidden { display: none !important; }

/* ---------- 로그인 ---------- */
#login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 400px; background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 32px 28px; box-shadow: 0 10px 30px rgba(20,22,28,.06); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 20px; }
.brand .egg { width: 34px; height: 34px; border-radius: 50% 50% 46% 46% / 58% 58% 42% 42%; background: var(--accent); display: grid; place-items: center; color: #fff; font-size: 15px; }
.login-card h1 { font-size: 22px; margin: 18px 0 4px; }
.login-card p.sub { color: var(--muted); margin: 0 0 22px; font-size: 14px; }
.names { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 16px; }
.names button { padding: 10px 4px; border: 1px solid var(--line); background: #fff; border-radius: 10px; }
.names button.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.pin { width: 100%; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; font-size: 18px; letter-spacing: .3em; text-align: center; }
.pin:focus, .composer textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.name-input { width: 100%; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; font-size: 16px; margin-bottom: 10px; }
.primary { width: 100%; margin-top: 12px; padding: 12px; border: 0; border-radius: 10px; background: var(--accent); color: #fff; font-weight: 700; }
.err { color: var(--bad); font-size: 14px; min-height: 22px; margin-top: 8px; }

/* ---------- 앱 레이아웃 ---------- */
#app { display: flex; height: 100%; }
aside { width: 272px; flex-shrink: 0; background: var(--side); color: var(--side-text); display: flex; flex-direction: column; }
aside .top { padding: 18px 16px 12px; }
aside .brand { color: #fff; font-size: 18px; }
.new-chat { width: 100%; margin-top: 14px; padding: 10px; border: 1px solid #343846; background: var(--side-2); color: #fff; border-radius: 10px; font-weight: 600; }
.new-chat:hover { border-color: var(--accent); }
.search { width: 100%; margin-top: 10px; padding: 8px 10px; border: 1px solid #343846; background: transparent; color: #fff; border-radius: 8px; }
.threads { flex: 1; overflow-y: auto; padding: 4px 8px 8px; }
.thread { display: flex; align-items: center; gap: 6px; padding: 8px 10px; border-radius: 8px; cursor: pointer; font-size: 14px; }
.thread:hover { background: var(--side-2); }
.thread.on { background: #2a2e39; color: #fff; }
.thread .t { flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.thread .x { visibility: hidden; border: 0; background: none; color: #8a90a0; padding: 0 4px; }
.thread:hover .x { visibility: visible; }
.thread .ic { width: 18px; text-align: center; }
.group-label { font-size: 12px; color: #7d8394; padding: 10px 10px 4px; }
aside .bottom { border-top: 1px solid #2a2e39; padding: 12px 16px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 13px; }
aside .bottom .who { flex: 1 0 100%; color: #fff; font-weight: 600; margin-bottom: 4px; }
.link { background: none; border: 1px solid #343846; color: var(--side-text); padding: 4px 9px; border-radius: 7px; font-size: 12px; }
.link:hover { color: #fff; border-color: #555b6b; }

main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
header.bar { display: flex; align-items: center; gap: 10px; padding: 10px 20px; border-bottom: 1px solid var(--line); background: var(--panel); }
.menu-btn { display: none; border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 4px 10px; }
header.bar .title { font-weight: 700; flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.sheet-dot { font-size: 12px; color: var(--muted); }

.modes { display: flex; gap: 6px; padding: 10px 20px; overflow-x: auto; background: var(--panel); border-bottom: 1px solid var(--line); scrollbar-width: thin; }
.chip { flex-shrink: 0; border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 5px 12px; font-size: 13px; color: var(--muted); }
.chip.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 700; }

#scroll { flex: 1; overflow-y: auto; }
.msgs { max-width: 880px; margin: 0 auto; padding: 24px 20px 40px; }

/* 시작 화면 */
.welcome h2 { font-size: 24px; margin: 8px 0 4px; }
.welcome p { color: var(--muted); margin: 0 0 20px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.card h3 { margin: 0 0 2px; font-size: 15px; }
.card .d { color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.ex { display: block; width: 100%; text-align: left; border: 0; background: var(--bg); border-radius: 8px; padding: 6px 10px; margin-top: 6px; font-size: 13px; color: var(--text); }
.ex:hover { background: var(--accent-soft); color: var(--accent); }

/* 메시지 */
.msg { margin: 0 0 22px; }
.msg.user { display: flex; flex-direction: column; align-items: flex-end; }
.bubble { background: var(--text); color: #fff; padding: 10px 14px; border-radius: 14px 14px 4px 14px; max-width: 85%; white-space: pre-wrap; }
.att-list { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; margin-bottom: 6px; }
.att { font-size: 12px; background: #fff; border: 1px solid var(--line); border-radius: 6px; padding: 2px 8px; color: var(--muted); }
.msg.ai .meta { font-size: 12px; color: var(--muted); margin-bottom: 4px; display: flex; gap: 6px; align-items: center; }
.badge { background: var(--accent-soft); color: var(--accent); border-radius: 6px; padding: 1px 7px; font-weight: 700; }
.body { background: var(--panel); border: 1px solid var(--line); border-radius: 4px 14px 14px 14px; padding: 14px 18px; }
.body > :first-child { margin-top: 0; }
.body > :last-child { margin-bottom: 0; }
.body h1, .body h2, .body h3 { line-height: 1.35; margin: 18px 0 8px; }
.body h1 { font-size: 20px; } .body h2 { font-size: 18px; } .body h3 { font-size: 16px; }
.body table { border-collapse: collapse; width: 100%; margin: 10px 0; font-size: 14px; display: block; overflow-x: auto; }
.body th, .body td { border: 1px solid var(--line); padding: 6px 9px; vertical-align: top; text-align: left; }
.body th { background: var(--bg); }
.body code { background: var(--code); padding: 1px 5px; border-radius: 4px; font-size: 13.5px; }
.body pre { position: relative; background: var(--code); padding: 12px 14px; border-radius: 10px; overflow-x: auto; white-space: pre-wrap; }
.body pre code { background: none; padding: 0; font-family: var(--font); font-size: 14px; }
.copy-code { position: absolute; top: 6px; right: 6px; border: 1px solid var(--line); background: #fff; border-radius: 6px; font-size: 12px; padding: 2px 8px; }
.body blockquote { margin: 10px 0; padding: 6px 12px; border-left: 3px solid var(--accent); background: var(--accent-soft); border-radius: 0 8px 8px 0; }
.body a { color: var(--accent); }
.status { color: var(--muted); font-size: 14px; display: flex; align-items: center; gap: 8px; padding: 6px 2px; }
.dots::after { content: "…"; animation: blink 1.2s infinite; }
@keyframes blink { 50% { opacity: .2; } }
.cursor::after { content: "▍"; color: var(--accent); animation: blink 1s infinite; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.act { border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 3px 10px; font-size: 13px; color: var(--muted); }
.act:hover { color: var(--text); border-color: #c4c8d2; }
.act.on { color: var(--accent); border-color: var(--accent); }

/* 자동 검수 */
.review { margin-top: 10px; border-radius: 10px; padding: 10px 14px; font-size: 14px; border: 1px solid; }
.review.pass { background: var(--ok-soft); border-color: #bfe5cc; }
.review.warn { background: var(--warn-soft); border-color: #f1dfae; }
.review.fail { background: var(--bad-soft); border-color: #f3c3be; }
.review.error { background: var(--bg); border-color: var(--line); }
.review .head { font-weight: 700; }
.review.pass .head { color: var(--ok); } .review.warn .head { color: var(--warn); } .review.fail .head { color: var(--bad); }
.review ul { margin: 6px 0 4px; padding-left: 18px; }
.review li { margin: 3px 0; }
.sev { font-weight: 700; margin-right: 4px; }
.fix-btn { margin-top: 6px; border: 0; background: var(--text); color: #fff; border-radius: 8px; padding: 5px 12px; font-size: 13px; }

/* 입력창 */
.composer-wrap { border-top: 1px solid var(--line); background: var(--panel); padding: 10px 20px 14px; }
.composer { max-width: 880px; margin: 0 auto; }
.pending { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.pending .att { display: flex; gap: 6px; align-items: center; }
.pending .att button { border: 0; background: none; padding: 0; color: var(--muted); }
.row { display: flex; gap: 8px; align-items: flex-end; border: 1px solid var(--line); border-radius: 14px; padding: 6px 6px 6px 8px; background: #fff; }
.row.drag { border-color: var(--accent); background: var(--accent-soft); }
.row textarea { flex: 1; border: 0; resize: none; max-height: 260px; min-height: 24px; padding: 6px 4px; line-height: 1.5; background: transparent; }
.row textarea:focus { outline: none; }
.icon-btn { border: 0; background: var(--bg); border-radius: 10px; width: 38px; height: 38px; font-size: 18px; flex-shrink: 0; }
.send { border: 0; background: var(--accent); color: #fff; border-radius: 10px; height: 38px; padding: 0 16px; font-weight: 700; flex-shrink: 0; }
.send.stop { background: var(--text); }
.hint { font-size: 12px; color: var(--muted); margin-top: 6px; display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }

/* 모달·관리자 */
.modal { position: fixed; inset: 0; background: rgba(20,22,28,.45); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal .box { background: var(--panel); border-radius: 16px; width: 100%; max-width: 980px; max-height: 90vh; overflow-y: auto; padding: 22px 24px; }
.modal .box.small { max-width: 380px; }
.modal h2 { margin: 0 0 12px; font-size: 20px; display: flex; justify-content: space-between; align-items: center; }
.close { border: 0; background: none; font-size: 22px; color: var(--muted); }
.stat-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-bottom: 18px; }
.stat { border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; }
.stat .n { font-size: 22px; font-weight: 800; }
.stat .l { font-size: 12px; color: var(--muted); }
.modal table { width: 100%; border-collapse: collapse; font-size: 14px; margin-bottom: 18px; }
.modal th, .modal td { border-bottom: 1px solid var(--line); padding: 7px 8px; text-align: left; vertical-align: top; }
.modal h3 { font-size: 15px; margin: 14px 0 6px; }
.modal input { width: 100%; padding: 10px; border: 1px solid var(--line); border-radius: 8px; margin-top: 8px; }
.toast { position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%); background: var(--text); color: #fff; padding: 8px 16px; border-radius: 10px; font-size: 14px; z-index: 60; }

.notice { font-size: 12px; color: var(--muted); margin: 14px 0 0; line-height: 1.5; }
.shade { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 39; }
.thread.touch .x { visibility: visible; }
.hint.formats { margin-top: 2px; }
.thumb { width: 28px; height: 28px; object-fit: cover; border-radius: 4px; }
.manual-copy { width: 100%; min-height: 220px; padding: 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 16px; }
.act.primary-act { color: var(--accent); border-color: #f4c7ab; background: var(--accent-soft); font-weight: 700; }
.opp { margin-top: 10px; border: 1px dashed #c4c8d2; border-radius: 10px; padding: 8px 12px; font-size: 14px; background: #fafbfc; white-space: pre-wrap; }
.opp .head { font-weight: 700; color: var(--muted); font-size: 12px; margin-bottom: 2px; }
.review .kind { font-weight: 700; font-size: 13px; margin-top: 8px; }
.review-wait { padding-top: 8px; }

.refs { margin-top: 8px; font-size: 13px; color: var(--muted); }
.refs summary { cursor: pointer; }
.refs li { margin: 2px 0; }
.esc { margin-top: 10px; border: 1px solid #c7d2fe; background: #eef2ff; border-radius: 10px; padding: 10px 14px; font-size: 14px; }
.esc .head { font-weight: 700; color: #3730a3; margin-bottom: 4px; }
.esc textarea { width: 100%; min-height: 110px; margin-top: 6px; padding: 8px 10px; border: 1px solid #c7d2fe; border-radius: 8px; font-family: inherit; font-size: 14px; }
.esc .sent { color: #3730a3; font-weight: 700; }
.esc .pre { white-space: pre-wrap; }
.esc .note { font-size: 12px; color: var(--muted); margin-top: 4px; }
.ceo-note { background: #fff8e6; border: 1px solid #f3d48a; border-radius: 12px; padding: 10px 14px; white-space: pre-wrap; font-size: 14px; }
.ceo-note .head { font-weight: 700; color: #92400e; }
.answers { margin: 0 8px 6px; background: #2a2e39; border-radius: 8px; padding: 8px 10px; font-size: 13px; color: #fde68a; cursor: pointer; }
.thread .dot { width: 8px; height: 8px; border-radius: 50%; background: #fbbf24; flex-shrink: 0; }

/* ---------- 모바일 ---------- */
@media (max-width: 820px) {
  aside { position: fixed; inset: 0 auto 0 0; z-index: 40; transform: translateX(-100%); transition: transform .2s; width: 82vw; max-width: 300px; }
  aside.open { transform: none; }
  .row textarea, .search, .pin, .modal input { font-size: 16px; } /* iPhone 입력 시 화면 확대 방지 */
  .hint.formats, #modeHint { display: none; } /* 좁은 화면에서는 입력칸을 넓게 — 형식 안내는 📎 누를 때 */
  .composer-wrap { padding-top: 8px; padding-bottom: 10px; }
  .menu-btn { display: block; }
  header.bar, .modes, .composer-wrap { padding-left: 16px; padding-right: 16px; }
  .msgs { padding: 16px 16px 32px; }
  .bubble { max-width: 92%; }
  .body { padding: 12px 14px; }
  .names { grid-template-columns: repeat(2, 1fr); }
}
