:root {
  --bg: #f7f5f0;
  --card: #ffffff;
  --text: #2a2a2a;
  --muted: #6b6b6b;
  --accent: #4a7c59;
  --accent-soft: #e6efe9;
  --user: #f0e6d2;
  --border: #e6e2d8;
  --sidebar-bg: #efece4;
  --sidebar-hover: #e3dfd3;
  --sidebar-active: #d9d3c1;
  --shadow: 0 1px 3px rgba(0,0,0,0.05);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Noto Sans KR", "Apple SD Gothic Neo", sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  height: 100vh;
  line-height: 1.6;
  overflow: hidden;
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: 260px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  padding: 16px 14px;
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin-bottom: 12px;
}
.logo { font-size: 20px; }
.brand-name { font-weight: 700; font-size: 18px; color: var(--accent); }

.new-chat-btn {
  width: 100%;
  background: var(--accent);
  color: white;
  border: none;
  padding: 9px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.new-chat-btn:hover { background: #3d6649; }

.session-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}
.session-empty {
  color: var(--muted);
  font-size: 13px;
  padding: 16px 8px;
  text-align: center;
}

.session-item {
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  margin-bottom: 4px;
  position: relative;
  transition: background 0.15s;
}
.session-item:hover { background: var(--sidebar-hover); }
.session-item.active { background: var(--sidebar-active); }

.session-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 4px;
}
.session-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  color: var(--muted);
}
.cli-badge {
  background: var(--accent-soft);
  color: var(--accent);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 600;
}
.session-delete {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 16px;
  opacity: 0;
  padding: 2px 6px;
  border-radius: 4px;
}
.session-item:hover .session-delete { opacity: 1; }
.session-delete:hover { background: rgba(0,0,0,0.08); color: #c44; }

.sidebar-footer {
  padding: 10px;
  font-size: 11px;
  color: var(--muted);
  text-align: center;
  border-top: 1px solid var(--border);
}

/* ---------- Main ---------- */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 20px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}
.chat-title {
  font-weight: 600;
  color: var(--text);
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 60%;
}

.topbar-right { display: flex; align-items: center; gap: 16px; }

.cli-picker { display: flex; align-items: center; gap: 6px; }

/* ---------- Auth (호스팅 모드에서만 활성) ---------- */
.auth-area {
  display: flex;
  align-items: center;
  gap: 8px;
}
.auth-email {
  font-size: 12px;
  color: var(--muted);
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.auth-btn {
  font-size: 12px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
  text-decoration: none;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--muted);
  transition: all 0.15s;
  line-height: 1.2;
}
.auth-btn:hover { border-color: var(--accent); color: var(--accent); }
.auth-login { background: var(--accent); color: white; border-color: var(--accent); }
.auth-login:hover { background: #3d6649; color: white; border-color: #3d6649; }

.cli-label { font-size: 12px; color: var(--muted); margin-right: 4px; }
.cli-btn {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--muted);
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 13px;
  transition: all 0.15s;
}
.cli-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.cli-btn.active { background: var(--accent); color: white; border-color: var(--accent); }
.cli-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.chat {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.chat-inner {
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
}

.message { display: flex; }
.message.user { justify-content: flex-end; }
.message.assistant { justify-content: flex-start; }

.bubble {
  max-width: 78%;
  padding: 12px 16px;
  border-radius: 16px;
  box-shadow: var(--shadow);
  white-space: pre-wrap;
  word-break: break-word;
}
.message.user .bubble { background: var(--user); border-bottom-right-radius: 4px; }
.message.assistant .bubble { background: var(--card); border-bottom-left-radius: 4px; }
.message.assistant.intro .bubble { background: var(--accent-soft); }

.markdown { white-space: normal; }
.markdown > *:first-child { margin-top: 0; }
.markdown > *:last-child { margin-bottom: 0; }
.markdown p { margin: 0 0 8px; line-height: 1.55; }
.markdown h1, .markdown h2, .markdown h3 { margin: 14px 0 6px; line-height: 1.3; }
.markdown h1 { font-size: 1.25em; }
.markdown h2 { font-size: 1.15em; }
.markdown h3 { font-size: 1.05em; }
.markdown ul, .markdown ol { margin: 6px 0 8px; padding-left: 22px; }
.markdown li { margin: 2px 0; line-height: 1.5; }
.markdown code { background: rgba(0,0,0,0.06); padding: 1px 5px; border-radius: 4px; font-size: 0.92em; }
.markdown pre { background: rgba(0,0,0,0.06); padding: 10px 12px; border-radius: 8px; overflow-x: auto; }
.markdown pre code { background: none; padding: 0; }
.markdown blockquote { margin: 6px 0; padding: 4px 12px; border-left: 3px solid var(--accent); color: #555; }
.markdown a { color: var(--accent); }
.markdown table { border-collapse: collapse; margin: 8px 0; }
.markdown th, .markdown td { border: 1px solid var(--border); padding: 4px 8px; }
.markdown hr { border: 0; border-top: 1px solid var(--border); margin: 12px 0; }

.cited {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
  font-size: 12px;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.cited-link {
  background: var(--accent-soft);
  color: var(--accent);
  padding: 3px 8px;
  border-radius: 6px;
  cursor: pointer;
  border: none;
  font-size: 12px;
}
.cited-link:hover { background: var(--accent); color: white; }

.typing { color: var(--muted); font-style: italic; }

/* ---------- Composer area ---------- */
.composer-area {
  border-top: 1px solid var(--border);
  background: var(--bg);
  padding: 12px 16px 8px;
}

.composer {
  display: flex;
  gap: 8px;
  max-width: 760px;
  margin: 0 auto;
  padding: 10px 14px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
}
.composer textarea {
  flex: 1;
  resize: none;
  border: none;
  outline: none;
  font-family: inherit;
  font-size: 15px;
  background: transparent;
}
.composer button {
  background: var(--accent);
  color: white;
  border: none;
  padding: 0 18px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
}
.composer button:disabled { opacity: 0.5; cursor: not-allowed; }

.readonly-banner {
  max-width: 760px;
  margin: 0 auto 8px;
  padding: 12px 16px;
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: 10px;
  color: var(--accent);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  font-size: 14px;
}
.readonly-banner button {
  background: var(--accent);
  color: white;
  border: none;
  padding: 6px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}

.disclaimer {
  max-width: 760px;
  margin: 6px auto 0;
  font-size: 11px;
  color: var(--muted);
  text-align: center;
}

.hidden { display: none !important; }

/* ---------- Modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 100;
  padding: 20px;
}
.modal-content {
  background: var(--card);
  border-radius: 12px;
  max-width: 720px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  padding: 24px 28px;
  position: relative;
}
.modal-close {
  position: absolute;
  top: 10px;
  right: 14px;
  background: none;
  border: none;
  font-size: 26px;
  cursor: pointer;
  color: var(--muted);
}
.modal h3 { margin-top: 0; color: var(--accent); }
.modal .meta { color: var(--muted); font-size: 13px; margin-bottom: 16px; }
.modal pre { white-space: pre-wrap; font-family: inherit; font-size: 14px; line-height: 1.7; }

/* ---------- Login modal (비로그인 차단) ---------- */
.login-modal-content {
  max-width: 380px;
  text-align: center;
  padding: 36px 28px 28px;
}
.login-logo {
  font-size: 44px;
  margin-bottom: 12px;
}
.login-modal-content h2 {
  margin: 0 0 10px;
  color: var(--accent);
  font-size: 20px;
}
.login-modal-content p {
  margin: 0 0 22px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}
.login-cta {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  padding: 11px 26px;
  border-radius: 6px;
  text-decoration: none;
  font-weight: 600;
  transition: background 0.15s;
}
.login-cta:hover { background: #3d6648; }
.login-note {
  margin-top: 22px !important;
  font-size: 12px;
  color: var(--muted);
}

/* ---------- Dedicated /login page ---------- */
.login-page {
  min-height: 100vh;
  margin: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 24px;
  background: var(--bg, #f6f7f5);
}
.login-card {
  background: #fff;
  max-width: 380px;
  width: 100%;
  padding: 44px 32px 28px;
  border-radius: 14px;
  box-shadow: 0 4px 28px rgba(0, 0, 0, 0.07);
  text-align: center;
}
.login-card .login-logo { font-size: 52px; line-height: 1; margin-bottom: 4px; }
.login-card h1 {
  margin: 0 0 4px;
  font-size: 28px;
  color: var(--accent);
}
.login-tagline {
  margin: 0 0 28px;
  font-size: 13px;
  color: var(--muted);
}

.sns-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  width: 100%;
  padding: 12px 16px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 10px;
  cursor: pointer;
  text-decoration: none;
  font-family: inherit;
  transition: background 0.15s, transform 0.1s;
}
.sns-btn:active { transform: translateY(1px); }
.sns-icon {
  position: absolute;
  left: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  font-weight: 700;
  border-radius: 4px;
  font-size: 13px;
}
.sns-label { line-height: 22px; }

.sns-google {
  background: #fff;
  border-color: #dadce0;
  color: #3c4043;
}
.sns-google:hover { background: #f8f9fa; }

.sns-kakao { background: #FEE500; color: #3a1d1d; }
.kakao-icon { background: #3a1d1d; color: #FEE500; }

.sns-naver { background: #03C75A; color: #fff; }
.naver-icon { background: #fff; color: #03C75A; }

.sns-btn[disabled] {
  cursor: not-allowed;
  opacity: 0.55;
}
.sns-btn[disabled]:hover { background: inherit; }

.sns-soon {
  position: absolute;
  right: 12px;
  font-size: 11px;
  font-weight: 500;
  padding: 2px 7px;
  background: rgba(0, 0, 0, 0.18);
  color: #fff;
  border-radius: 999px;
}
.sns-kakao .sns-soon { background: rgba(58, 29, 29, 0.65); }

.login-disclaimer {
  margin-top: 28px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
}
