* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg-primary: #ffffff;
  --bg-secondary: #f7f7f8;
  --bg-sidebar: #ffffff;
  --bg-input: #404040;
  --text-primary: #1a1a1a;
  --text-secondary: #666666;
  --border: #d6d6d7;
  --accent: #10a37f;
  --accent-hover: #0e906e;
  --user-msg-bg: #ffffff;
  --assistant-msg-bg: #f7f7f8;
  --tool-msg-bg: #e7f4ee;
  --thinking-msg-bg: #fffbeb;
  --danger: #dc2626;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

html, body, #app {
  height: 100%;
  width: 100%;
  font-family: var(--font);
  background-color: var(--bg-secondary);
  color: var(--text-primary);
}

.view {
  display: none;
  height: 100%;
  width: 100%;
}

.view.hidden {
  display: none;
}

/* ---------- 인증 ---------- */
.auth-view {
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--bg-secondary);
}

.auth-card {
  background: var(--bg-primary);
  padding: 40px 32px;
  border-radius: 16px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  width: 100%;
  max-width: 400px;
}

.auth-card h1 {
  font-size: 28px;
  margin-bottom: 8px;
  font-weight: 700;
}

.auth-card p {
  color: var(--text-secondary);
  margin-bottom: 24px;
}

.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 24px;
}

.tab {
  flex: 1;
  padding: 10px;
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
}

.tab.active {
  background: var(--bg-primary);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 14px;
  margin-bottom: 6px;
  color: var(--text-secondary);
}

.form-group input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  outline: none;
}

.form-group input:focus {
  border-color: var(--accent);
}

.form-hint {
  display: block;
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 4px;
}

.btn {
  padding: 10px 16px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-primary {
  background: var(--accent);
  color: white;
  width: 100%;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-primary);
  width: 100%;
  margin-top: 10px;
}

.btn-outline:hover {
  background: var(--bg-secondary);
}

.btn.small {
  padding: 6px 12px;
  font-size: 13px;
  width: auto;
}

.btn-row {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.btn-row.tight {
  gap: 6px;
  margin-top: 4px;
}

.btn-row .btn {
  flex: 1;
  margin: 0;
}

.msg {
  margin-top: 12px;
  font-size: 13px;
  color: var(--danger);
  min-height: 18px;
}

.toggle-text {
  margin-top: 16px;
  font-size: 14px;
  color: var(--text-secondary);
  text-align: center;
}

.toggle-text .link {
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
}

/* 라디오 그룹 */
.radio-group {
  display: flex;
  gap: 12px;
  margin-top: 4px;
}

.radio-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  color: var(--text-primary);
  cursor: pointer;
}

.radio-label input {
  width: auto;
  margin: 0;
}

/* ---------- 모델 검색 / 제조사 필터 ---------- */
.model-search-wrap {
  position: relative;
  margin-bottom: 8px;
}

.model-search-wrap input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  outline: none;
}

.model-search-wrap input:focus {
  border-color: var(--accent);
}

.vendor-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.vendor-filter {
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-primary);
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
}

.vendor-filter:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.vendor-filter.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

/* ---------- 메인 앱 ---------- */
.main-view {
  display: flex;
  height: 100%;
  overflow: hidden;
}

.sidebar {
  width: 360px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden; /* 사이드바 전체 스크롤 */
}

.sidebar-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

.sidebar-header h2 {
  font-size: 20px;
  font-weight: 700;
}

.settings-panel {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
  flex-shrink: 0;
  overflow-y: auto;
  max-height: 40vh;
}

.settings-group {
  margin-bottom: 16px;
}

.settings-label {
  display: block;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 6px;
  font-weight: 600;
}

.settings-group select,
#project-select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-primary);
  font-size: 14px;
  outline: none;
}

#project-select {
  margin-bottom: 8px;
}

.conversations {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
}

.conversations h3 {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 12px;
  font-weight: 600;
}

#conversation-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.conv-item {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  background: var(--bg-primary);
  transition: all 0.2s;
}

.conv-item:hover {
  border-color: var(--accent);
  background: var(--bg-secondary);
}

.conv-item.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.conv-item .conv-title {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-item .conv-time {
  font-size: 11px;
  opacity: 0.7;
  margin-top: 4px;
  display: block;
}

.conv-item .conv-project {
  font-size: 10px;
  opacity: 0.6;
  margin-top: 2px;
  display: block;
}

/* ---------- 채팅 ---------- */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-secondary);
  overflow: hidden;
}

.chat-header {
  padding: 16px 24px;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-shrink: 0;
}

.chat-header .title-info {
  flex: 1;
}

.chat-header #current-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 4px;
}

.project-badge {
  font-size: 12px;
  background: #e7f4ee;
  color: var(--accent);
  padding: 4px 10px;
  border-radius: 12px;
  border: 1px solid #b9e3d4;
  font-weight: 600;
  white-space: nowrap;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.message {
  max-width: 700px;
  width: fit-content;
}

.message.user {
  align-self: flex-end;
}

.message.assistant {
  align-self: flex-start;
}

.message-bubble {
  padding: 14px 18px;
  border-radius: 16px;
  font-size: 15px;
  line-height: 1.6;
  white-space: pre-wrap;
}

.message.user .message-bubble {
  background: var(--accent);
  color: white;
  border-bottom-right-radius: 4px;
}

.message.assistant .message-bubble {
  background: var(--assistant-msg-bg);
  border-bottom-left-radius: 4px;
}

.message-meta {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 6px;
  margin-left: 4px;
}

/* 도구 실행 표시 */
.tool-call {
  background: var(--tool-msg-bg);
  border: 1px solid #b9e3d4;
  border-radius: 10px;
  padding: 10px 14px;
  margin-top: 10px;
  font-size: 13px;
  line-height: 1.5;
}

.tool-call .tool-name {
  font-weight: 700;
  color: var(--accent);
  display: block;
  margin-bottom: 4px;
}

.tool-call pre {
  background: rgba(0, 0, 0, 0.05);
  padding: 8px;
  border-radius: 6px;
  overflow-x: auto;
  margin-top: 4px;
  white-space: pre-wrap;
  word-break: break-all;
}

.thinking {
  background: var(--thinking-msg-bg);
  border-left: 3px solid #f59e0b;
  padding: 8px 12px;
  margin-top: 8px;
  border-radius: 0 6px 6px 0;
  font-size: 13px;
  color: #92400e;
  font-style: italic;
}

/* 시스템 메시지 */
.system-msg {
  background: #e3f2fd;
  border-left: 3px solid #2196f3;
  padding: 8px 12px;
  margin-top: 8px;
  border-radius: 0 6px 6px 0;
  font-size: 13px;
  color: #1565c0;
  font-style: italic;
}

/* ---------- 입력 ---------- */
.chat-input-area {
  padding: 16px 24px;
  background: var(--bg-primary);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.input-wrapper {
  max-width: 900px;
  margin: 0 auto;
  position: relative;
  display: flex;
  gap: 10px;
}

#message-input {
  flex: 1;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 14px;
  outline: none;
  resize: none;
  min-height: 44px;
  max-height: 120px;
  font-family: inherit;
}

#message-input:focus {
  border-color: var(--accent);
}

.send-btn {
  padding: 12px 24px;
  background: var(--accent);
  color: white;
  border-radius: 20px;
  font-weight: 600;
  white-space: nowrap;
}

.send-btn:hover {
  background: var(--accent-hover);
}

.send-btn:disabled {
  background: #c7c7c7;
  cursor: not-allowed;
}

/* 로딩/스트리밍 커서 */
.typing-indicator {
  display: inline-block;
}

.typing-indicator::after {
  content: "";
  animation: typing 1.4s infinite both;
}

@keyframes typing {
  0%, 60%, 100% {
    transform: translateY(0);
  }
  30% {
    transform: translateY(-4px);
  }
}

/* ---------- 유틸 ---------- */
.hidden {
  display: none !important;
}

.link {
  cursor: pointer;
  color: var(--accent);
  text-decoration: underline;
}

/* 모바일 */
@media (max-width: 768px) {
  .sidebar {
    width: 280px;
  }
  .messages {
    padding: 16px;
  }
  .message {
    max-width: 85%;
  }
  .chat-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }
  .project-badge {
    align-self: flex-start;
  }
  .radio-group {
    flex-direction: column;
    gap: 8px;
  }
  .vendor-filters {
    justify-content: center;
  }
}