:root {
  --bg: #131314;
  --bg-elev: #1e1e20;
  --bg-input: #2a2a2d;
  --line: #34343a;
  --text: #ececf1;
  --text-dim: #9a9aa5;
  --accent: #c96442;
  --accent-2: #d97757;
  --user-bubble: #2f6fed;
  --ok: #3fb950;
  --warn: #d29922;
  --danger: #f85149;
  --radius: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Apple SD Gothic Neo",
    "Noto Sans KR", sans-serif;
  font-size: 16px;
  overscroll-behavior: none;
}

.hidden {
  display: none !important;
}

/* ── 로그인 ── */
.login {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 360px;
  text-align: center;
}
.login-logo {
  font-size: 44px;
  color: var(--accent-2);
  margin-bottom: 8px;
}
.login-logo img {
  width: 84px;
  height: 84px;
  border-radius: 20px;
  display: inline-block;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
}
.login-card h1 {
  font-size: 24px;
  margin: 0 0 4px;
}
.login-sub {
  color: var(--text-dim);
  margin: 0 0 28px;
  font-size: 14px;
}
#login-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
#password {
  height: 52px;
  padding: 0 16px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg-input);
  color: var(--text);
  font-size: 16px;
  outline: none;
}
#password:focus {
  border-color: var(--accent);
}
#login-btn {
  height: 52px;
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
}
#login-btn:active {
  background: var(--accent-2);
}
.login-error {
  margin-top: 14px;
  color: var(--danger);
  font-size: 14px;
  min-height: 18px;
}

/* ── 채팅 레이아웃 ── */
.chat {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(var(--safe-top) + 10px) 14px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  flex: none;
}
.topbar-info {
  display: flex;
  align-items: center;
  gap: 8px;
}
.topbar-title {
  font-size: 15px;
  font-weight: 600;
}
.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--text-dim);
}
.dot.on {
  background: var(--ok);
}
.dot.off {
  background: var(--danger);
}
.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--text);
  font-size: 22px;
  line-height: 1;
}
.icon-btn:active {
  background: var(--bg-input);
}
/* 토글 켜짐 표시(대화만 보기 등) */
.icon-btn.active {
  background: var(--accent, #c96343);
  border-color: var(--accent, #c96343);
}

/* 대화만 보기: 도구 호출/결과 카드 숨김(대화 말풍선만 표시) */
.messages.conv-only .tool {
  display: none;
}

/* ── 메시지 ── */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  -webkit-overflow-scrolling: touch;
}
.row {
  display: flex;
  max-width: 100%;
}
.row.user {
  justify-content: flex-end;
}
.bubble {
  max-width: 86%;
  padding: 11px 14px;
  border-radius: var(--radius);
  line-height: 1.55;
  word-break: break-word;
  white-space: normal;
  font-size: 15.5px;
}
.row.user .bubble {
  background: var(--user-bubble);
  color: #fff;
  border-bottom-right-radius: 5px;
}
.row.assistant .bubble {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-bottom-left-radius: 5px;
}
.bubble p {
  margin: 0 0 8px;
}
.bubble p:last-child {
  margin-bottom: 0;
}
.bubble code.inline {
  background: rgba(255, 255, 255, 0.1);
  padding: 1px 5px;
  border-radius: 5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.9em;
}
.bubble pre {
  background: #0d0d0f;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  overflow-x: auto;
  margin: 8px 0;
}
.bubble pre code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  line-height: 1.5;
  white-space: pre;
}
.bubble h1,
.bubble h2,
.bubble h3,
.bubble h4,
.bubble h5,
.bubble h6 {
  margin: 10px 0 6px;
  font-weight: 700;
  line-height: 1.3;
}
.bubble h1 { font-size: 1.4em; }
.bubble h2 { font-size: 1.2em; }
.bubble h3 { font-size: 1.08em; }
.bubble h4,
.bubble h5,
.bubble h6 { font-size: 1em; }
.bubble ul,
.bubble ol {
  margin: 6px 0;
  padding-left: 22px;
}
.bubble li {
  margin: 2px 0;
}
.bubble blockquote {
  margin: 8px 0;
  padding: 2px 0 2px 12px;
  border-left: 3px solid var(--accent-2, rgba(255, 255, 255, 0.4));
  color: rgba(255, 255, 255, 0.75);
}
.bubble hr {
  border: none;
  border-top: 1px solid var(--line);
  margin: 12px 0;
}
.bubble .md-table {
  border-collapse: collapse;
  margin: 8px 0;
  font-size: 0.92em;
  width: auto;
}
.bubble .md-table th,
.bubble .md-table td {
  border: 1px solid var(--line);
  padding: 5px 10px;
  text-align: left;
  vertical-align: top;
}
.bubble .md-table th {
  background: rgba(255, 255, 255, 0.06);
  font-weight: 600;
}
.cursor::after {
  content: "▍";
  color: var(--accent-2);
  animation: blink 1s steps(2) infinite;
}
@keyframes blink {
  50% {
    opacity: 0;
  }
}

/* 사고중 표시 */
.thinking {
  color: var(--text-dim);
  font-style: italic;
  font-size: 14px;
}

/* ── 도구 카드 ── */
.tool {
  align-self: flex-start;
  max-width: 86%;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 13.5px;
}
.tool-head {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-dim);
}
.tool-name {
  font-weight: 600;
  color: var(--text);
}
.tool-summary {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12.5px;
  color: var(--text-dim);
  margin-top: 6px;
  word-break: break-all;
  white-space: pre-wrap;
}
.tool.result .tool-summary {
  max-height: 160px;
  overflow-y: auto;
}
.tool.err {
  border-color: var(--danger);
}
.tool .badge {
  margin-left: auto;
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--bg-input);
  color: var(--text-dim);
}
.tool .badge.ok {
  color: var(--ok);
}
.tool .badge.deny {
  color: var(--danger);
}

/* 승인 카드 */
.perm {
  align-self: flex-start;
  max-width: 92%;
  background: var(--bg-elev);
  border: 1px solid var(--warn);
  border-radius: 14px;
  padding: 14px;
}
.perm-title {
  font-weight: 700;
  margin-bottom: 4px;
}
.perm-sub {
  color: var(--text-dim);
  font-size: 13px;
  margin-bottom: 8px;
}
.perm-cmd {
  background: #0d0d0f;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  white-space: pre-wrap;
  word-break: break-all;
  margin-bottom: 12px;
  max-height: 180px;
  overflow-y: auto;
}
.perm-actions {
  display: flex;
  gap: 10px;
}
.perm-actions button {
  flex: 1;
  height: 46px;
  border-radius: 10px;
  border: none;
  font-size: 15px;
  font-weight: 600;
}
.btn-allow {
  background: var(--ok);
  color: #04210c;
}
.btn-deny {
  background: var(--bg-input);
  color: var(--text);
}
.perm.resolved {
  opacity: 0.6;
  border-color: var(--line);
}

/* ── 세션 목록 드로어 ── */
.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 40;
}
.drawer {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 82%;
  max-width: 340px;
  background: var(--bg-elev);
  border-right: 1px solid var(--line);
  z-index: 50;
  transform: translateX(-100%);
  transition: transform 0.22s ease;
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-top);
}
.drawer.open {
  transform: translateX(0);
}
.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--line);
}
.drawer-title {
  font-size: 17px;
  font-weight: 700;
}
.drawer-new {
  border: 1px solid var(--line);
  background: var(--accent);
  color: #fff;
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 14px;
  font-weight: 600;
}
.drawer-new:active {
  background: var(--accent-2);
}
.project-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
}
.project-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted, #888);
  white-space: nowrap;
}
.project-select {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--line);
  background: var(--bg-input, #2a2a2d);
  color: var(--text, #ececf1);
  border-radius: 8px;
  padding: 7px 9px;
  font-size: 14px;
}
.session-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  -webkit-overflow-scrolling: touch;
}
.session-empty {
  color: var(--text-dim);
  font-size: 14px;
  text-align: center;
  padding: 32px 16px;
}
.session-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px;
  border-radius: 12px;
  margin-bottom: 4px;
  border: 1.5px solid transparent;
}
.session-item.active {
  border-color: #c96442;
}
.session-item:active {
  background: var(--bg-input);
}
.session-main {
  flex: 1;
  min-width: 0;
}
.session-title {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.session-preview {
  font-size: 13px;
  color: var(--text-dim);
  margin-top: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* 프로젝트 구분 헤더(섹션) */
.session-group-head {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 12px 4px;
  border-top: 1px solid var(--line);
  margin-top: 6px;
}
.session-list > .session-group-head:first-child {
  border-top: none;
  margin-top: 0;
}
.session-group-name {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.session-group-count {
  font-size: 11px;
  color: var(--text-dim);
  opacity: 0.7;
}
.session-del {
  flex: none;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 14px;
}
.session-del:active {
  background: var(--bg-input);
  color: var(--danger);
}
.drawer-foot {
  border-top: 1px solid var(--line);
  padding: 12px 16px calc(var(--safe-bottom) + 12px);
}
.workspace-info {
  font-size: 12px;
  color: var(--text-dim);
}

/* ── 입력창 ── */
.composer {
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 12px calc(var(--safe-bottom) + 8px);
  background: var(--bg);
  border-top: 1px solid var(--line);
}
.composer-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}
.quick-replies {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding: 2px;
}
.quick-replies::-webkit-scrollbar {
  display: none;
}
.quick-chip {
  flex: none;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg-input);
  color: var(--text);
  font-size: 13px;
  white-space: nowrap;
  cursor: pointer;
}
.quick-chip.edit {
  color: var(--text-dim);
}
.quick-chip.suggest {
  color: var(--accent);
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  font-weight: 600;
}
/* 빠른 답변 편집 모달 (1문구 = 1블록) */
.qr-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
}
.qr-sheet {
  width: 100%;
  max-width: 420px;
  max-height: 80vh;
  overflow-y: auto;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.qr-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.qr-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}
.qr-hint {
  font-size: 13px;
  color: var(--text-dim);
}
.qr-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.qr-block {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-input);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 4px 6px 4px 12px;
}
.qr-input {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 15px;
  padding: 8px 0;
  outline: none;
}
.qr-del {
  flex: none;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-dim);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}
.qr-del:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
}
.qr-add {
  border: 1px dashed var(--line);
  border-radius: 12px;
  background: transparent;
  color: var(--accent);
  font-size: 14px;
  font-weight: 500;
  padding: 11px;
  cursor: pointer;
}
.qr-add:hover {
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}
.qr-reset {
  align-self: flex-start;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 13px;
  cursor: pointer;
  padding: 2px;
}
.qr-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}
.qr-btn {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg-input);
  color: var(--text);
  font-size: 14px;
  padding: 8px 16px;
  cursor: pointer;
}
.qr-save {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}
.auto-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--text-dim);
  padding-left: 4px;
}
.auto-toggle input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}
#input {
  flex: 1;
  resize: none;
  max-height: 140px;
  padding: 12px 14px;
  border-radius: 20px;
  border: 1px solid var(--line);
  background: var(--bg-input);
  color: var(--text);
  font-size: 16px;
  line-height: 1.4;
  outline: none;
  font-family: inherit;
}
#input:focus {
  border-color: var(--accent);
}
.attach-btn {
  width: 46px;
  height: 46px;
  flex: none;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--bg-input);
  color: var(--text-dim);
  font-size: 22px;
  font-weight: 700;
  cursor: pointer;
}
.attach-preview {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding: 2px;
}
.attach-preview::-webkit-scrollbar {
  display: none;
}
/* 붙여넣은 긴 텍스트 칩(전송 시 전체 원문이 본문에 합쳐짐) */
.paste-preview {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding: 2px;
}
.paste-preview::-webkit-scrollbar {
  display: none;
}
.paste-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: none;
  max-width: 100%;
  padding: 7px 11px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--line);
  font-size: 13px;
  white-space: nowrap;
}
.paste-chip .remove {
  border: none;
  background: transparent;
  color: var(--muted, #888);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}
.attach-thumb {
  position: relative;
  flex: none;
  width: 60px;
  height: 60px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--line);
}
.attach-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.attach-thumb .remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  font-size: 12px;
  line-height: 18px;
  text-align: center;
  cursor: pointer;
  padding: 0;
}
.bubble .msg-img {
  display: block;
  max-width: 220px;
  max-height: 260px;
  border-radius: 12px;
  margin-bottom: 6px;
}
.send-btn,
.stop-btn {
  width: 46px;
  height: 46px;
  flex: none;
  border-radius: 50%;
  border: none;
  font-size: 20px;
  font-weight: 700;
  color: #fff;
}
.send-btn {
  background: var(--accent);
}
.send-btn:disabled {
  background: var(--bg-input);
  color: var(--text-dim);
}
.stop-btn {
  background: var(--danger);
  font-size: 15px;
}

.sys-note {
  align-self: center;
  color: var(--text-dim);
  font-size: 12.5px;
  padding: 4px 0;
}
