/* 로컬 RAG 게시판 데모 — 앱 셸 스타일 */

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans KR", sans-serif;
  background: #f3f4f6;
  color: #1f2937;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.hidden {
  display: none !important;
}

/* ---------- 모바일 안내 오버레이 ---------- */

#mobile-overlay {
  display: none;
}

@media (max-width: 767px) {
  #mobile-overlay {
    display: flex;
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: #1e293b;
    align-items: center;
    justify-content: center;
    padding: 24px;
  }

  .mobile-card {
    background: #ffffff;
    border-radius: 12px;
    padding: 28px 24px;
    text-align: center;
    max-width: 320px;
  }

  .mobile-card h1 {
    margin: 0 0 10px;
    font-size: 18px;
    color: #1e293b;
  }

  .mobile-card p {
    margin: 0;
    font-size: 14px;
    line-height: 1.7;
    color: #475569;
  }
}

/* ---------- 상단바 ---------- */

.topbar {
  background: #1e293b;
  color: #f8fafc;
  height: 52px;
  flex: 0 0 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  gap: 12px;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.logo {
  font-size: 17px;
  font-weight: 700;
  color: #f8fafc;
  text-decoration: none;
  white-space: nowrap;
}

.current-view {
  font-size: 13px;
  color: #94a3b8;
  border-left: 1px solid #334155;
  padding-left: 14px;
  white-space: nowrap;
}

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

.credit-chip {
  background: #f59e0b;
  color: #1e293b;
  border: none;
  border-radius: 14px;
  padding: 5px 12px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

.credit-chip:hover {
  background: #fbbf24;
}

.user-area {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
}

.user-area:hover {
  background: #334155;
}

.user-name {
  font-size: 13px;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.panel-toggles {
  display: flex;
  gap: 4px;
  border-left: 1px solid #334155;
  padding-left: 8px;
}

.panel-toggle {
  background: transparent;
  border: 1px solid #475569;
  color: #cbd5e1;
  border-radius: 6px;
  width: 28px;
  height: 28px;
  font-size: 13px;
  cursor: pointer;
  line-height: 1;
}

.panel-toggle:hover {
  background: #334155;
  color: #f8fafc;
}

/* ---------- 본문 셸 ---------- */

.shell {
  flex: 1;
  display: flex;
  min-height: 0;
}

/* 좌측 네비게이션 */

.left-nav {
  flex: 0 0 210px;
  background: #ffffff;
  border-right: 1px solid #e5e7eb;
  overflow-y: auto;
  padding: 12px 8px;
}

body.hide-left .left-nav {
  display: none;
}

.nav-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.nav-item {
  display: block;
  padding: 10px 14px;
  margin-bottom: 2px;
  border-radius: 8px;
  color: #374151;
  text-decoration: none;
  font-size: 14px;
}

.nav-item:hover {
  background: #f3f4f6;
}

.nav-item.active {
  background: #1e293b;
  color: #f8fafc;
  font-weight: 600;
}

/* 중앙 뷰 */

.view {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  padding: 16px 20px;
}

/* 우측 Gemini 패널 */

.gemini-panel {
  flex: 0 0 330px;
  background: #ffffff;
  border-left: 1px solid #e5e7eb;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

body.hide-right .gemini-panel {
  display: none;
}

.gemini-head {
  padding: 12px 14px;
  border-bottom: 1px solid #e5e7eb;
}

.gemini-head h2 {
  margin: 0;
  font-size: 15px;
  color: #1e293b;
}

.gemini-head .hint {
  margin: 4px 0 0;
  font-size: 11px;
  color: #6b7280;
}

.gemini-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.gemini-notice {
  padding: 16px 14px;
  font-size: 13px;
  line-height: 1.7;
  color: #475569;
}

.gemini-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.bubble {
  max-width: 88%;
  border-radius: 12px;
  padding: 8px 12px;
  font-size: 13px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

.bubble.user {
  align-self: flex-end;
  background: #2563eb;
  color: #ffffff;
  border-bottom-right-radius: 4px;
}

.bubble.gemini {
  align-self: flex-start;
  background: #f1f5f9;
  color: #1f2937;
  border-bottom-left-radius: 4px;
}

.bubble.error {
  align-self: flex-start;
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #b91c1c;
}

.bubble .bubble-link {
  display: inline-block;
  margin-top: 6px;
  font-size: 12px;
  color: #2563eb;
  cursor: pointer;
  text-decoration: underline;
  background: none;
  border: none;
  padding: 0;
}

.gemini-input-row {
  display: flex;
  gap: 6px;
  padding: 10px 12px;
  border-top: 1px solid #e5e7eb;
}

.gemini-input-row textarea {
  flex: 1;
  resize: none;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  padding: 7px 10px;
  font-family: inherit;
  font-size: 13px;
}

/* 하단 상태바 */

.status-bar {
  flex: 0 0 30px;
  background: #1e293b;
  color: #94a3b8;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 16px;
  font-size: 12px;
  overflow-x: auto;
  white-space: nowrap;
}

body.hide-bottom .status-bar {
  display: none;
}

.status-item.ok {
  color: #86efac;
}

.status-item.bad {
  color: #f87171;
}

/* ---------- 공통 컴포넌트 ---------- */

.card {
  background: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
}

.card-title {
  margin: 0 0 12px;
  font-size: 16px;
  border-bottom: 1px solid #e5e7eb;
  padding-bottom: 8px;
  color: #1e293b;
}

.section-title {
  margin: 4px 0 10px;
  font-size: 15px;
  color: #1e293b;
}

.hint {
  font-size: 11px;
  font-weight: normal;
  color: #6b7280;
  margin-left: 6px;
}

.btn {
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}

.btn-sm {
  padding: 5px 12px;
  font-size: 13px;
}

.btn-primary {
  background: #2563eb;
  color: #ffffff;
}

.btn-primary:hover:not(:disabled) {
  background: #1d4ed8;
}

.btn-ghost {
  background: transparent;
  border-color: #475569;
  color: inherit;
}

.btn-outline {
  background: #ffffff;
  border-color: #d1d5db;
  color: #374151;
}

.btn-outline:hover:not(:disabled) {
  background: #f9fafb;
}

.btn:disabled {
  background: #9ca3af;
  border-color: transparent;
  color: #f3f4f6;
  cursor: not-allowed;
}

.btn-ghost:disabled {
  background: transparent;
  color: #64748b;
}

input[type="text"],
input[type="url"],
input[type="number"],
textarea {
  border: 1px solid #d1d5db;
  border-radius: 6px;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 14px;
  width: 100%;
}

input:focus,
textarea:focus {
  outline: 2px solid #bfdbfe;
  outline-offset: 0;
  border-color: #2563eb;
}

.form-row {
  margin-bottom: 12px;
}

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: #374151;
  margin-bottom: 4px;
}

.error-box {
  margin-top: 10px;
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #b91c1c;
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 13px;
  white-space: pre-wrap;
}

.error-box .btn {
  margin-top: 8px;
}

.info-box {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  color: #1d4ed8;
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.7;
}

.success-box {
  margin-top: 10px;
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  color: #166534;
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 13px;
}

.avatar {
  border-radius: 50%;
  object-fit: cover;
  background: #e2e8f0;
}

.avatar-sm {
  width: 26px;
  height: 26px;
}

.avatar-lg {
  width: 56px;
  height: 56px;
}

.avatar-fallback {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #1e293b;
  color: #f8fafc;
  font-weight: 700;
  font-size: 13px;
}

.avatar-lg.avatar-fallback {
  font-size: 22px;
}

/* 토스트 */

#toast {
  position: fixed;
  top: 64px;
  left: 50%;
  transform: translateX(-50%) translateY(-8px);
  background: #1e293b;
  color: #f8fafc;
  border-radius: 8px;
  padding: 10px 18px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 900;
}

#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---------- 대시보드 / 공개 Q&A 피드 ---------- */

.welcome-card {
  display: flex;
  align-items: center;
  gap: 16px;
}

.welcome-card .welcome-text {
  flex: 1;
  min-width: 0;
}

.welcome-card h2 {
  margin: 0 0 6px;
  font-size: 18px;
}

.welcome-card p {
  margin: 0 0 10px;
  font-size: 13px;
  color: #475569;
  line-height: 1.7;
}

.welcome-stats {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.stat-chip {
  background: #f1f5f9;
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 13px;
  color: #334155;
}

.stat-chip b {
  color: #1e293b;
}

.qa-feed {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.qa-card {
  background: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 14px 16px;
}

.qa-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.qa-author {
  font-size: 13px;
  font-weight: 600;
  color: #334155;
}

.qa-date {
  font-size: 11px;
  color: #9ca3af;
  margin-left: auto;
}

.qa-question {
  margin: 0 0 8px;
  font-size: 14px;
  font-weight: 700;
  color: #1e293b;
}

.qa-answer {
  margin: 0 0 8px;
  font-size: 13px;
  line-height: 1.7;
  color: #374151;
  white-space: pre-wrap;
}

.qa-citations {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  font-size: 12px;
  color: #6b7280;
}

.cite-chip {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  color: #166534;
  border-radius: 10px;
  padding: 2px 8px;
  font-size: 11px;
  cursor: pointer;
}

.cite-chip:hover {
  background: #dcfce7;
}

.empty-box {
  background: #ffffff;
  border: 1px dashed #d1d5db;
  border-radius: 8px;
  padding: 24px;
  text-align: center;
  color: #6b7280;
  font-size: 13px;
}

/* ---------- AI 질문 뷰 ---------- */

.ask-grid {
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  gap: 16px;
  align-items: start;
}

.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.suggestion {
  font-size: 12px;
  border: 1px solid #c7d2fe;
  background: #eef2ff;
  color: #3730a3;
  border-radius: 14px;
  padding: 4px 10px;
  cursor: pointer;
}

.suggestion:hover {
  background: #e0e7ff;
}

.ask-row {
  display: flex;
  gap: 8px;
}

.ask-row textarea {
  flex: 1;
  resize: none;
}

.loading {
  margin-top: 10px;
  font-size: 13px;
  color: #2563eb;
}

.answer-area {
  margin-top: 12px;
}

.answer-area h3 {
  margin: 12px 0 6px;
  font-size: 14px;
}

.answer-text {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  padding: 10px 12px;
  white-space: pre-wrap;
  line-height: 1.6;
  font-size: 14px;
  margin: 0;
}

.citation-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.citation-item {
  border: 1px solid #bbf7d0;
  background: #f0fdf4;
  border-radius: 6px;
  padding: 8px 10px;
  margin-bottom: 6px;
  font-size: 13px;
  cursor: pointer;
}

.citation-item:hover {
  background: #dcfce7;
}

.citation-score {
  color: #16a34a;
  font-weight: 700;
  margin-left: 6px;
}

/* 검색된 게시글 강조 목록 */

.retrieved-box {
  margin-top: 12px;
  border: 1px solid #bbf7d0;
  background: #f0fdf4;
  border-radius: 6px;
  padding: 8px 12px;
}

.retrieved-box h4 {
  margin: 0 0 6px;
  font-size: 12px;
  color: #166534;
}

.retrieved-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  padding: 3px 0;
  cursor: pointer;
}

.retrieved-item:hover {
  text-decoration: underline;
}

/* 처리 로그 */

.ask-log {
  display: flex;
  flex-direction: column;
  min-height: 420px;
  max-height: calc(100vh - 140px);
  position: sticky;
  top: 0;
}

.log-box {
  flex: 1;
  overflow-y: auto;
  background: #0f172a;
  border-radius: 6px;
  padding: 10px 12px;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.7;
  min-height: 220px;
}

.log-line {
  white-space: pre-wrap;
  word-break: break-all;
  color: #cbd5e1;
}

.log-time {
  color: #64748b;
}

.log-stage {
  display: inline-block;
  min-width: 96px;
  font-weight: 700;
}

.log-info {
  color: #64748b;
}

/* 단계별 색상 */
.stage-REQUEST        { color: #60a5fa; } /* 파란색 */
.stage-RAG            { color: #c084fc; } /* 이전 단계명 호환 */
.stage-RAG_INIT       { color: #c084fc; } /* 복라색 */
.stage-EMBEDDING      { color: #c084fc; }
.stage-RETRIEVAL      { color: #c084fc; }
.stage-RESULT         { color: #4ade80; } /* 녹색 */
.stage-PROMPT         { color: #2dd4bf; } /* 청록색 */
.stage-API            { color: #fb923c; } /* 이전 단계명 호환 */
.stage-OLLAMA_CONNECT { color: #fb923c; } /* 주황색 */
.stage-LLM            { color: #facc15; } /* 이전 단계명 호환 */
.stage-LLM_INFERENCE  { color: #facc15; } /* 노란색 */
.stage-RESPONSE_BUILD { color: #34d399; } /* 에메랄드 */
.stage-COMPLETE       { color: #86efac; } /* 밝은 녹색 */
.stage-ERROR          { color: #f87171; } /* 빨간색 */

.stage-time {
  color: #64748b;
  font-size: 11px;
  margin-left: 6px;
}

/* 실행 요약 */

.run-summary {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: 6px;
  padding: 8px 12px;
  margin-bottom: 8px;
  font-size: 12px;
  line-height: 1.8;
  color: #166534;
}

.run-summary b {
  color: #14532d;
}

/* 개발모드 모델정보 */

.dev-info {
  margin-top: 8px;
  background: #f8fafc;
  border: 1px dashed #94a3b8;
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 11px;
  line-height: 1.7;
  color: #475569;
  white-space: pre-wrap;
}

/* ---------- 게시판 ---------- */

.post-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.post-item {
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  padding: 10px 12px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: background 0.15s;
}

.post-item:hover {
  background: #f9fafb;
}

.post-item.selected {
  border-color: #2563eb;
}

/* RAG 검색에서 선택된 게시글 강조 */
.post-item.retrieved {
  background: #dcfce7;
  border-color: #16a34a;
}

.post-item-head {
  display: flex;
  align-items: center;
  gap: 8px;
}

.post-id {
  font-weight: 700;
  color: #2563eb;
  min-width: 30px;
}

.post-title {
  font-weight: 600;
  flex: 1;
}

.post-category {
  font-size: 11px;
  background: #e0e7ff;
  color: #3730a3;
  border-radius: 10px;
  padding: 2px 8px;
  white-space: nowrap;
}

.post-date {
  font-size: 11px;
  color: #6b7280;
  margin-top: 4px;
}

.score-badge {
  font-size: 11px;
  background: #16a34a;
  color: #ffffff;
  border-radius: 10px;
  padding: 2px 8px;
  margin-left: 6px;
  white-space: nowrap;
}

.post-detail {
  margin-top: 12px;
  border-top: 2px solid #e5e7eb;
  padding-top: 12px;
}

.post-detail h3 {
  margin: 0;
  font-size: 15px;
}

.post-detail-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.post-meta {
  font-size: 11px;
  color: #6b7280;
  white-space: nowrap;
}

.post-content {
  white-space: pre-wrap;
  line-height: 1.6;
  font-size: 14px;
}

/* ---------- 구독/크레딧 ---------- */

.policy-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.policy-table th,
.policy-table td {
  border: 1px solid #e5e7eb;
  padding: 8px 12px;
  text-align: left;
}

.policy-table th {
  background: #f8fafc;
  color: #475569;
  font-weight: 600;
  width: 40%;
}

.plan-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.plan-card {
  border: 2px solid #e5e7eb;
  border-radius: 10px;
  padding: 16px;
  text-align: center;
  background: #ffffff;
}

.plan-card.current {
  border-color: #2563eb;
  background: #eff6ff;
}

.plan-name {
  font-size: 16px;
  font-weight: 700;
  color: #1e293b;
}

.plan-price {
  font-size: 20px;
  font-weight: 800;
  color: #2563eb;
  margin: 8px 0 2px;
}

.plan-period {
  font-size: 11px;
  color: #9ca3af;
}

.plan-credits {
  font-size: 13px;
  color: #475569;
  margin: 10px 0;
}

.current-badge {
  display: inline-block;
  background: #2563eb;
  color: #ffffff;
  border-radius: 10px;
  padding: 2px 10px;
  font-size: 11px;
  font-weight: 700;
  margin-bottom: 8px;
}

/* ---------- 마이페이지 ---------- */

.mypage-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  align-items: start;
}

.profile-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.profile-email {
  font-size: 13px;
  color: #6b7280;
}

.link-row {
  display: flex;
  gap: 6px;
  margin-bottom: 6px;
}

.link-row input {
  flex: 1;
}

.history-toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.history-toolbar input {
  flex: 1;
  min-width: 180px;
}

.history-item {
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 8px;
}

.history-q {
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  color: #1e293b;
}

.history-q:hover {
  color: #2563eb;
}

.history-meta {
  font-size: 11px;
  color: #6b7280;
  margin-top: 4px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.history-actions {
  display: flex;
  gap: 6px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.history-answer {
  margin-top: 10px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.7;
  white-space: pre-wrap;
}

.public-badge {
  font-size: 11px;
  border-radius: 10px;
  padding: 1px 8px;
  background: #e0e7ff;
  color: #3730a3;
}

.public-badge.private {
  background: #f1f5f9;
  color: #64748b;
}

/* ---------- 관리자 ---------- */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 12px;
}

.stat-card {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 10px 12px;
}

.stat-card .stat-label {
  font-size: 11px;
  color: #64748b;
}

.stat-card .stat-value {
  font-size: 18px;
  font-weight: 800;
  color: #1e293b;
  margin-top: 2px;
  word-break: break-all;
}

.admin-note {
  font-size: 12px;
  color: #6b7280;
  line-height: 1.7;
  margin: 8px 0 0;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.data-table th,
.data-table td {
  border: 1px solid #e5e7eb;
  padding: 6px 10px;
  text-align: left;
  white-space: nowrap;
}

.data-table th {
  background: #f8fafc;
  color: #475569;
  font-weight: 600;
}

.policy-form-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  margin-bottom: 12px;
}

/* 좁은 화면 대응 (태블릿은 PC와 동일, 1200px 미만에서만 약간 조정) */

@media (max-width: 1199px) {
  .gemini-panel {
    flex-basis: 300px;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .policy-form-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .mypage-grid,
  .ask-grid {
    grid-template-columns: 1fr;
  }

  .ask-log {
    position: static;
    max-height: none;
  }
}
