* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
  background: #f4f2ee;
  color: #2b2b2b;
}
.hidden { display: none !important; }

/* ---------- 접근 코드 게이트 ---------- */
.gate {
  position: fixed; inset: 0; z-index: 100;
  background: linear-gradient(160deg, #1a1a2e, #16213e);
  display: flex; align-items: center; justify-content: center;
}
.gate-card {
  background: #fff; border-radius: 20px; padding: 44px 48px;
  text-align: center; max-width: 380px; width: calc(100% - 40px);
  box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
.gate-card h1 { margin: 0 0 10px; font-size: 24px; }
.gate-card p { color: #666; font-size: 15px; margin: 0 0 20px; }
#gate-input {
  width: 100%; font-size: 32px; letter-spacing: 12px; text-align: center;
  padding: 12px; border: 2px solid #ddd; border-radius: 12px;
  font-family: ui-monospace, monospace; outline: none;
}
#gate-input:focus { border-color: #c96f4a; }
#gate-btn {
  width: 100%; margin-top: 16px; padding: 14px; font-size: 17px; font-weight: 700;
  background: #c96f4a; color: #fff; border: none; border-radius: 12px; cursor: pointer;
}
#gate-btn:hover { background: #b55e3b; }
.gate-error { color: #d33; font-size: 14px; min-height: 20px; margin: 12px 0 0 !important; }

/* ---------- 레이아웃 ---------- */
.app { display: flex; flex-direction: column; height: 100dvh; max-width: 860px; margin: 0 auto; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; background: #f4f2ee; border-bottom: 1px solid #e3ded5;
}
.brand { display: flex; align-items: center; gap: 10px; }
.logo { font-size: 26px; }
.title { font-weight: 800; font-size: 17px; }
.subtitle { font-size: 12px; color: #999; }
.btn-ghost {
  background: none; border: 1px solid #d8d2c6; border-radius: 10px;
  padding: 8px 14px; font-size: 14px; cursor: pointer; color: #555;
}
.btn-ghost:hover { background: #ece8df; }

/* ---------- 메시지 ---------- */
.messages { flex: 1; overflow-y: auto; padding: 24px 20px 12px; }
.welcome { text-align: center; color: #888; margin-top: 12vh; }
.welcome h2 { color: #444; }

.msg { margin-bottom: 20px; display: flex; flex-direction: column; }
.msg.user { align-items: flex-end; }
.msg.assistant { align-items: flex-start; }
.bubble {
  max-width: 92%; padding: 12px 16px; border-radius: 16px;
  line-height: 1.65; font-size: 15px; overflow-wrap: break-word;
}
.msg.user .bubble { background: #c96f4a; color: #fff; white-space: pre-wrap; border-bottom-right-radius: 4px; }
.msg.assistant .bubble { background: #fff; border: 1px solid #e6e1d7; border-bottom-left-radius: 4px; width: 100%; max-width: 100%; }

.attach-tags { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; }
.attach-tag {
  font-size: 12px; background: #ece5da; color: #6b5d4a;
  padding: 4px 10px; border-radius: 20px;
}

/* 생각 과정 */
details.thinking {
  margin: 0 0 10px; font-size: 13px; color: #999;
  background: #faf8f4; border: 1px dashed #ddd6c8; border-radius: 10px; padding: 8px 12px;
}
details.thinking summary { cursor: pointer; user-select: none; }
details.thinking .thinking-body { white-space: pre-wrap; margin-top: 8px; line-height: 1.5; }

/* 마크다운 */
.bubble h1, .bubble h2, .bubble h3 { margin: 18px 0 8px; }
.bubble p { margin: 8px 0; }
.bubble ul, .bubble ol { margin: 8px 0; padding-left: 24px; }
.bubble table { border-collapse: collapse; margin: 10px 0; display: block; overflow-x: auto; }
.bubble th, .bubble td { border: 1px solid #ddd; padding: 6px 12px; font-size: 14px; }
.bubble th { background: #f5f2ec; }
.bubble code:not(pre code) {
  background: #f0ece4; padding: 2px 6px; border-radius: 5px;
  font-family: ui-monospace, 'SF Mono', Consolas, monospace; font-size: 13.5px; color: #b5462a;
}
.bubble blockquote { border-left: 3px solid #d8cfc0; margin: 8px 0; padding-left: 12px; color: #777; }

/* ---------- 코드 블록 ---------- */
.code-card { margin: 12px 0; border-radius: 10px; overflow: hidden; border: 1px solid #2d333b; }
.code-head {
  display: flex; align-items: center; justify-content: space-between;
  background: #21262d; color: #adbac7; padding: 6px 12px; font-size: 12.5px;
}
.code-lang { font-family: ui-monospace, monospace; text-transform: lowercase; }
.code-actions { display: flex; gap: 6px; }
.code-actions button {
  background: #30363d; color: #cdd9e5; border: none; border-radius: 6px;
  padding: 4px 10px; font-size: 12px; cursor: pointer;
}
.code-actions button:hover { background: #444c56; }
.code-card pre { margin: 0; }
.code-card pre code {
  display: block; padding: 14px 16px; overflow-x: auto;
  font-family: ui-monospace, 'SF Mono', Consolas, monospace; font-size: 13.5px; line-height: 1.55;
}

/* ---------- 입력창 ---------- */
.composer-wrap { padding: 8px 16px 10px; background: #f4f2ee; }
.attach-list { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.attach-chip {
  display: flex; align-items: center; gap: 6px; font-size: 13px;
  background: #fff; border: 1px solid #ddd6c8; border-radius: 20px; padding: 5px 12px;
}
.attach-chip button { background: none; border: none; cursor: pointer; color: #999; font-size: 14px; padding: 0; }
.composer {
  display: flex; align-items: flex-end; gap: 8px;
  background: #fff; border: 1px solid #ddd6c8; border-radius: 18px; padding: 8px 10px;
  box-shadow: 0 2px 10px rgba(0,0,0,.05);
}
.btn-icon { background: none; border: none; font-size: 20px; cursor: pointer; padding: 8px; }
#input {
  flex: 1; border: none; outline: none; resize: none; font-size: 15px;
  font-family: inherit; line-height: 1.5; max-height: 180px; padding: 8px 0; background: transparent;
}
.btn-send {
  background: #c96f4a; color: #fff; border: none; border-radius: 12px;
  width: 42px; height: 42px; font-size: 17px; cursor: pointer; flex-shrink: 0;
}
.btn-send:disabled { background: #d9cfc2; cursor: not-allowed; }
.btn-send.stop { background: #555; }
.hint { text-align: center; font-size: 11.5px; color: #b0a898; margin-top: 6px; }

.error-bubble { background: #fdecec !important; border-color: #f5c6c6 !important; color: #a33; }

/* ---------- 메시지 도구 (수정 / 다시 생성) ---------- */
.topbar-actions { display: flex; gap: 8px; }
.msg-tools { margin-top: 4px; opacity: 0; transition: opacity .15s; }
.msg:hover .msg-tools { opacity: 1; }
@media (hover: none) { .msg-tools { opacity: .7; } }
.msg-tools button, .regen-row button {
  background: none; border: 1px solid #ddd6c8; border-radius: 8px;
  padding: 3px 10px; font-size: 12px; color: #8a8272; cursor: pointer;
}
.msg-tools button:hover, .regen-row button:hover { background: #ece8df; color: #555; }
.regen-row { margin-top: 6px; }

/* ---------- HTML 미리보기 모달 ---------- */
.preview-modal {
  position: fixed; inset: 0; z-index: 95; background: rgba(0,0,0,.5);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.preview-card {
  background: #fff; border-radius: 14px; overflow: hidden;
  width: min(960px, 100%); height: min(700px, 100%);
  display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.4);
}
.preview-head {
  display: flex; align-items: center; justify-content: space-between;
  background: #21262d; color: #cdd9e5; padding: 8px 14px; font-size: 14px; font-weight: 600;
}
.preview-actions { display: flex; gap: 8px; }
.preview-actions button {
  background: #30363d; color: #cdd9e5; border: none; border-radius: 6px;
  padding: 5px 12px; font-size: 12.5px; cursor: pointer;
}
.preview-actions button:hover { background: #444c56; }
#preview-frame { flex: 1; border: none; width: 100%; background: #fff; }

/* ---------- 드래그 앤 드롭 오버레이 ---------- */
.drop-overlay {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(201, 111, 74, .12);
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
}
.drop-box {
  border: 3px dashed #c96f4a; border-radius: 20px; background: #fff;
  padding: 36px 56px; font-size: 20px; font-weight: 700; color: #c96f4a;
  box-shadow: 0 10px 40px rgba(0,0,0,.15);
}

@media (max-width: 600px) {
  .bubble { max-width: 100%; }
  .gate-card { padding: 32px 24px; }
}
