/* === 디자인 토큰 === */
:root {
  --primary-gold: #C9A843;
  --dark-gold: #9E832E;
  --light-gold: #FFF8E1;
  --accent: #E25822;
  --bg-color: #F5F5F0;
  --text-color: #333;
  --card-bg: #FFFFFF;
  --card-border: #E8E2D0;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
}

/* === 기본 리셋 === */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background-color: var(--bg-color);
  color: var(--text-color);
  -webkit-font-smoothing: antialiased;
}

/* === 앱 컨테이너 (전체 화면 구조) === */
#app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100%;
  max-width: 540px;
  margin: 0 auto;
  background-color: var(--bg-color);
  position: relative;
}

@media (min-width: 600px) {
  #app-container {
    height: 96vh;
    margin-top: 2vh;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    overflow: hidden;
  }
}

/* === 상단 고정 헤더 === */
#fixed-top {
  position: sticky;
  top: 0;
  flex-shrink: 0;
  z-index: 100;
  background: var(--bg-color);
}

#fixed-top header {
  background: linear-gradient(135deg, var(--primary-gold) 0%, var(--dark-gold) 100%);
  color: white;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between; /* 로고 중앙, 아이콘 우측 */
  position: relative;
}

/* 로고 - 절대 중앙 배치 */
.header-logo {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: white;
}

/* 좌측 여백 (대칭 유지용) */
#fixed-top header::before {
  content: '';
  width: 72px; /* header-icons 너비와 동일하게 */
}

#fixed-top header img {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.6);
  object-fit: cover;
}

#fixed-top header span {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 0.5px;
}

/* 우측 아이콘 버튼 */
.header-icons {
  display: flex;
  gap: 4px;
  z-index: 1;
}

.header-icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: rgba(255,255,255,0.2);
  text-decoration: none;
  font-size: 18px;
  transition: background 0.2s;
}

.header-icon-btn:hover {
  background: rgba(255,255,255,0.35);
}

/* === 검색 영역 === */
#search-bar {
  padding: 12px 16px;
  background: var(--card-bg);
  border-bottom: 1px solid var(--card-border);
}

#search-bar .greeting {
  color: var(--dark-gold);
  font-size: 15px;
  font-weight: 600;
  text-align: center;
  margin: 0 0 10px 0;
}

#search-bar .input-row {
  display: flex;
  gap: 8px;
  max-width: 480px;
  margin: 0 auto;
}

#user-input {
  flex: 1;
  padding: 10px 14px;
  border: 2px solid var(--accent);
  border-radius: var(--radius-sm);
  font-size: 14px;
  outline: none;
  background: white;
  transition: border-color 0.2s, box-shadow 0.2s;
}

#user-input:focus {
  border-color: #C53D12;
  box-shadow: 0 0 0 3px rgba(226, 88, 34, 0.15);
}

#send-btn {
  background: var(--primary-gold);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  padding: 0 16px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  white-space: nowrap;
}

#send-btn:hover { background: var(--dark-gold); }
#send-btn:active { transform: scale(0.97); }

/* === 채팅 영역 (스크롤) === */
#chat-box {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--bg-color);
  -webkit-overflow-scrolling: touch;
}

/* === 메뉴 버튼 === */
.top-menu {
  display: flex;
  gap: 10px;
}

.menu-btn {
  flex: 1;
  text-align: center;
  background: var(--dark-gold);
  color: white;
  padding: 11px 8px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  font-weight: 700;
  font-size: 13px;
  box-shadow: var(--shadow-sm);
  transition: background 0.2s, transform 0.1s;
}
.menu-btn:hover { background: #87711F; transform: translateY(-1px); }

/* === 카드 공통 === */
.card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: var(--shadow-sm);
}

.card h3 {
  margin: 0 0 8px 0;
  color: var(--dark-gold);
  font-size: 15px;
  padding-bottom: 6px;
  border-bottom: 1px solid #f0ead8;
}

/* === 일정 박스 === */
.schedule-box {
  max-height: 280px;
  overflow-y: auto;
}

.schedule-box .warning {
  font-size: 12px;
  color: #D32F2F;
  font-weight: 600;
  margin-bottom: 8px;
}

#schedule-content {
  font-size: 14px;
  line-height: 1.7;
  white-space: pre-wrap;
}

/* === 사찰 연락처 === */
.temple-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.temple-item {
  background: var(--light-gold);
  padding: 10px;
  border-radius: var(--radius-sm);
}

.temple-item .name {
  font-weight: 700;
  font-size: 13px;
  margin-bottom: 6px;
  color: var(--text-color);
}

.temple-item .call-btn {
  display: inline-block;
  background: var(--dark-gold);
  color: white;
  padding: 4px 10px;
  border-radius: 4px;
  text-decoration: none;
  font-size: 11px;
  font-weight: 600;
  transition: background 0.2s;
}
.temple-item .call-btn:hover { background: #87711F; }

/* === 웰컴 메시지 === */
.welcome-msg {
  background: var(--card-bg);
  padding: 20px;
  border-radius: var(--radius-md);
  font-size: 15px;
  line-height: 1.7;
  text-align: center;
  border: 2px solid var(--primary-gold);
  box-shadow: 0 4px 12px rgba(201, 168, 67, 0.1);
}

.welcome-footer {
  margin-top: 16px;
  font-size: 13px;
  color: #999;
  line-height: 1.5;
}

.welcome-footer hr {
  border: 0;
  border-top: 1px solid rgba(0,0,0,0.06);
  margin-bottom: 12px;
}

.welcome-footer a {
  color: #888;
  font-weight: 600;
  text-decoration: underline;
}

.welcome-footer .donate {
  cursor: pointer;
  text-decoration: underline;
}

/* === 채팅 메시지 === */
.message {
  max-width: 88%;
  padding: 14px 18px;
  border-radius: var(--radius-lg);
  font-size: 16px;
  line-height: 1.65;
  word-break: break-word;
  box-shadow: var(--shadow-sm);
}

.message.user {
  align-self: flex-end;
  background: var(--primary-gold);
  color: white;
  border-bottom-right-radius: 4px;
  font-weight: 500;
}

.message.bot {
  align-self: flex-start;
  background: var(--card-bg);
  color: var(--text-color);
  border-bottom-left-radius: 4px;
  border: 1px solid var(--card-border);
  white-space: pre-wrap;
}

/* === 출처 카드 (답변 내) === */
.citation-card {
  margin: 6px 0;
  padding: 8px 10px;
  background: var(--light-gold);
  border-left: 3px solid var(--primary-gold);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: #444;
  display: block;
  white-space: normal;
}

.citation-card .cite-title {
  font-weight: 700;
  color: var(--dark-gold);
  margin-bottom: 1px;
  font-size: 12px;
  line-height: 1.4;
}

.citation-card .cite-meta {
  font-size: 11px;
  color: #777;
  margin-bottom: 6px;
  display: block;
}

.citation-card a {
  display: flex;
  align-items: center;
  gap: 7px;
  text-decoration: none;
}

.citation-card img {
  width: 100%;
  max-width: 160px;
  height: auto;
  aspect-ratio: 16 / 9;
  border-radius: 6px;
  object-fit: cover;
  flex-shrink: 0;
  border: 1px solid rgba(0,0,0,0.05);
}

.citation-card .cite-link {
  color: var(--dark-gold);
  font-weight: 700;
  font-size: 11px;
  text-decoration: underline;
}

/* === 링크 === */
.citation-link {
  color: var(--dark-gold);
  font-weight: bold;
  text-decoration: underline;
  word-break: break-all;
}
.citation-link:hover { color: #87711F; }

/* === 로딩 스피너 === */
#loading-indicator {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 20px;
}

.loader {
  border: 3px solid #eee;
  border-top: 3px solid var(--primary-gold);
  border-radius: 50%;
  width: 30px;
  height: 30px;
  animation: spin 0.8s linear infinite;
}

.loading-text {
  font-size: 14px;
  color: var(--dark-gold);
  font-weight: 600;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* === 하단 추천 영상 === */
.featured-video {
  padding: 0;
  overflow: hidden;
  margin-bottom: 20px;
}

.featured-video h3 {
  padding: 12px 16px;
  margin: 0;
  border-bottom: 1px solid var(--card-border);
}

.featured-video a {
  text-decoration: none;
  display: block;
}

.video-container {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
}

.video-container img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0.9;
  transition: opacity 0.2s;
}

.featured-video a:hover img {
  opacity: 1;
}

.play-overlay {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 50px;
  height: 50px;
  background: rgba(226, 88, 34, 0.9);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  box-shadow: 0 4px 10px rgba(0,0,0,0.3);
  transition: transform 0.2s;
}

.featured-video a:hover .play-overlay {
  transform: translate(-50%, -50%) scale(1.1);
}

.video-title {
  padding: 12px 16px;
  font-size: 14px;
  font-weight: 700;
  color: var(--text-color);
  background: white;
  text-align: center;
}

/* === 푸터 === (기존 푸터 스타일 제거 및 정리) */
.footer-info {
  display: none;
}

/* === 답변 후 네비게이션 버튼 === */
.chat-nav-btns {
  display: flex;
  gap: 8px;
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--card-border);
}

.nav-btn {
  flex: 1;
  padding: 10px 8px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  background: var(--light-gold);
  color: var(--dark-gold);
  border: 1px solid var(--primary-gold);
}

.nav-btn:hover {
  background: #f0e6a0;
  transform: translateY(-1px);
}

.nav-btn-home {
  background: var(--dark-gold);
  color: white;
  border-color: var(--dark-gold);
}

.nav-btn-home:hover {
  background: #87711F;
}

/* === Admin Page === */
.admin-container {
  padding: 40px 30px;
  background-color: white;
  flex: 1;
}
.admin-container h2 {
  color: var(--primary-gold);
  font-size: 24px;
  margin-bottom: 10px;
}
.admin-container p {
  font-size: 18px;
  color: #666;
  margin-bottom: 25px;
}
.admin-container input, .admin-container textarea {
  width: 100%;
  padding: 18px;
  margin-bottom: 20px;
  border: 2px solid #ddd;
  border-radius: 12px;
  font-size: 18px;
  box-sizing: border-box;
}
.admin-container input:focus, .admin-container textarea:focus {
  border-color: var(--primary-gold);
  outline: none;
}
.admin-container button {
  width: 100%;
  padding: 18px;
  background-color: var(--primary-gold);
  color: white;
  font-size: 20px;
  font-weight: bold;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  transition: background-color 0.2s;
}
.admin-container button:hover {
  background-color: var(--dark-gold);
}
