:root {
  --primary: #1a3a5c;
  --accent: #e63946;
  --bg: #f8f9fa;
  --surface: #ffffff;
  --border: #dee2e6;
  --text: #212529;
  --muted: #6c757d;
  --sidebar-width: 260px;
}

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

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
}

/* ── 헤더 ── */
header {
  background: var(--primary);
  color: #fff;
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 20px;
  height: 60px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,.3);
}

header .logo {
  font-size: 1.3rem;
  font-weight: 700;
  text-decoration: none;
  color: #fff;
  white-space: nowrap;
}

header .logo span { color: #f4d03f; }

.search-bar {
  flex: 1;
  max-width: 480px;
  display: flex;
  gap: 8px;
}

.search-bar input {
  flex: 1;
  padding: 8px 14px;
  border: none;
  border-radius: 20px;
  font-size: .95rem;
  outline: none;
}

.search-bar button {
  padding: 8px 18px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 20px;
  cursor: pointer;
  font-weight: 600;
  transition: opacity .2s;
}
.search-bar button:hover { opacity: .85; }

/* ── 레이아웃 ── */
.layout {
  display: flex;
  min-height: calc(100vh - 60px);
}

/* ── 사이드바 ── */
aside {
  width: var(--sidebar-width);
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px 0;
  position: sticky;
  top: 60px;
  height: calc(100vh - 60px);
  overflow-y: auto;
  flex-shrink: 0;
}

.sidebar-section { margin-bottom: 8px; }

.sidebar-section .conf-header {
  padding: 8px 20px;
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sidebar-section .conf-header:hover { color: var(--primary); }

.sidebar-section ul {
  list-style: none;
  display: none;
}

.sidebar-section.open ul { display: block; }

.sidebar-section ul li a {
  display: block;
  padding: 5px 20px 5px 32px;
  text-decoration: none;
  color: var(--text);
  font-size: .9rem;
  transition: background .15s;
}

.sidebar-section ul li a:hover,
.sidebar-section ul li a.active {
  background: #e8f0fe;
  color: var(--primary);
  font-weight: 600;
}

.host-badge {
  font-size: .65rem;
  background: var(--accent);
  color: #fff;
  padding: 1px 5px;
  border-radius: 3px;
  margin-left: 5px;
}

/* ── 메인 콘텐츠 ── */
main {
  flex: 1;
  padding: 36px 48px;
  max-width: 900px;
}

/* ── 홈 그리드 ── */
.home-hero {
  background: linear-gradient(135deg, var(--primary) 0%, #2c5f8a 100%);
  color: #fff;
  border-radius: 12px;
  padding: 40px;
  margin-bottom: 40px;
  text-align: center;
}

.home-hero h1 { font-size: 2rem; margin-bottom: 10px; }
.home-hero p { opacity: .85; font-size: 1.1rem; }
.home-hero .stats { display: flex; justify-content: center; gap: 40px; margin-top: 24px; }
.home-hero .stat strong { display: block; font-size: 2rem; font-weight: 700; color: #f4d03f; }
.home-hero .stat span { font-size: .85rem; opacity: .8; }

.conf-section { margin-bottom: 40px; }
.conf-section h2 {
  font-size: 1.1rem;
  color: var(--primary);
  border-left: 4px solid var(--accent);
  padding-left: 12px;
  margin-bottom: 16px;
}

.country-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 14px;
}

.country-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 12px;
  text-align: center;
  text-decoration: none;
  color: var(--text);
  transition: transform .2s, box-shadow .2s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.country-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 6px 18px rgba(0,0,0,.1);
  border-color: var(--primary);
}

.country-card img {
  width: 64px;
  height: 42px;
  object-fit: cover;
  border-radius: 4px;
  border: 1px solid var(--border);
}

.country-card .flag-placeholder {
  width: 64px;
  height: 42px;
  background: var(--bg);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
}

.country-card .name { font-weight: 600; font-size: .9rem; }
.country-card .desc { font-size: .75rem; color: var(--muted); line-height: 1.3; }
.country-card .host-tag {
  font-size: .7rem;
  background: var(--accent);
  color: #fff;
  padding: 2px 7px;
  border-radius: 10px;
}

/* ── 국가 상세 페이지 ── */
.country-content h1 { font-size: 2rem; color: var(--primary); margin-bottom: 6px; }
.country-content h2 {
  font-size: 1.25rem;
  color: var(--primary);
  margin: 28px 0 10px;
  padding-bottom: 6px;
  border-bottom: 2px solid var(--border);
}
.country-content h3 { font-size: 1rem; margin: 20px 0 8px; }
.country-content p { margin-bottom: 14px; }
.country-content blockquote {
  background: #fff8e1;
  border-left: 4px solid #f4d03f;
  padding: 12px 16px;
  border-radius: 0 6px 6px 0;
  margin: 16px 0;
}
.country-content hr { border: none; border-top: 1px solid var(--border); margin: 24px 0; }
.country-content a { color: var(--primary); }

.country-flag {
  max-width: 220px;
  border-radius: 6px;
  border: 1px solid var(--border);
  margin: 12px 0;
}

/* ── 검색 결과 ── */
.search-results h2 { margin-bottom: 20px; color: var(--primary); }
.result-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px 20px;
  margin-bottom: 12px;
  text-decoration: none;
  color: var(--text);
  display: block;
  transition: border-color .2s;
}
.result-item:hover { border-color: var(--primary); }
.result-item strong { font-size: 1.1rem; color: var(--primary); }
.result-item p { color: var(--muted); font-size: .9rem; margin-top: 4px; }

/* ── 404 ── */
.error-page { text-align: center; padding: 80px 20px; }
.error-page h1 { font-size: 5rem; color: var(--accent); font-weight: 900; }
.error-page p { font-size: 1.1rem; color: var(--muted); margin: 16px 0 24px; }
.error-page a {
  background: var(--primary);
  color: #fff;
  padding: 10px 24px;
  border-radius: 6px;
  text-decoration: none;
}

/* ── 위키 테이블 ── */
.table-wrap {
  overflow-x: auto;
  margin: 16px 0;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.wiki-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .88rem;
}

.wiki-table th {
  background: var(--primary);
  color: #fff;
  padding: 9px 12px;
  text-align: left;
  font-weight: 600;
  white-space: nowrap;
}

.wiki-table td {
  padding: 7px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.wiki-table tr:last-child td { border-bottom: none; }
.wiki-table tr:nth-child(even) td { background: #f8f9fa; }
.wiki-table tr:hover td { background: #e8f0fe; }

/* ── AI 채팅 패널 (2026 공인구 Täljestenen 테마) ── */

/* 공인구 색상 */
:root {
  --ball-navy:  #081428;
  --ball-gold:  #E8A020;
  --ball-red:   #C8401A;
  --ball-cream: #F0EDE6;
}

.chat-toggle {
  position: fixed;
  bottom: 28px;
  right: 28px;
  width: 62px;
  height: 62px;
  background: var(--ball-navy);
  border: 2.5px solid var(--ball-gold);
  border-radius: 50%;
  cursor: pointer;
  z-index: 200;
  box-shadow: 0 4px 18px rgba(8,20,40,.45), 0 0 0 4px rgba(232,160,32,.15);
  transition: transform .25s, box-shadow .25s;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.chat-toggle:hover {
  transform: scale(1.1) rotate(15deg);
  box-shadow: 0 6px 24px rgba(8,20,40,.6), 0 0 0 6px rgba(232,160,32,.2);
}
.chat-toggle svg { display: block; }

.chat-panel {
  position: fixed;
  top: 60px;
  right: 0;
  width: 380px;
  height: calc(100vh - 60px);
  background: var(--surface);
  border-left: 2px solid var(--ball-gold);
  display: flex;
  flex-direction: column;
  z-index: 150;
  transform: translateX(100%);
  transition: transform .3s ease;
  box-shadow: -6px 0 28px rgba(8,20,40,.2);
}
.chat-panel.open { transform: translateX(0); }

/* 헤더: 공인구 기하학 패턴 */
.chat-header {
  padding: 14px 18px;
  background: var(--ball-navy);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
  border-bottom: 2px solid var(--ball-gold);
}
/* 헥사곤 패턴 오버레이 */
.chat-header::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(60deg,  rgba(232,160,32,.07) 25%, transparent 25%),
    linear-gradient(120deg, rgba(232,160,32,.07) 25%, transparent 25%),
    linear-gradient(60deg,  transparent 75%, rgba(232,160,32,.07) 75%),
    linear-gradient(120deg, transparent 75%, rgba(232,160,32,.07) 75%);
  background-size: 28px 16px;
  pointer-events: none;
}
/* 골드 사선 강조 */
.chat-header::after {
  content: '';
  position: absolute;
  right: -30px;
  top: -30px;
  width: 90px;
  height: 90px;
  background: rgba(232,160,32,.1);
  transform: rotate(45deg);
  pointer-events: none;
}
.chat-header-inner {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 10px;
}
.chat-header-ball {
  flex-shrink: 0;
}
.chat-header h3 { font-size: 1rem; font-weight: 600; margin: 0; }
.chat-header .model-tag {
  font-size: .7rem;
  background: rgba(232,160,32,.25);
  color: var(--ball-gold);
  padding: 2px 8px;
  border-radius: 10px;
  border: 1px solid rgba(232,160,32,.4);
}
.chat-close {
  background: none;
  border: none;
  color: rgba(255,255,255,.7);
  font-size: 1.3rem;
  cursor: pointer;
  padding: 2px 6px;
  position: relative;
  z-index: 1;
  transition: color .15s;
}
.chat-close:hover { color: var(--ball-gold); }

/* 관련 국가 카드 영역 */
.related-cards {
  flex-shrink: 0;
  max-height: 160px;
  overflow-y: auto;
  padding: 10px 12px;
  background: #f0f4ff;
  border-bottom: 1px solid var(--border);
  display: none;
  gap: 8px;
  flex-wrap: wrap;
}
.related-cards.visible { display: flex; }
.related-card {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #fff;
  border: 1px solid #c0d0f0;
  border-radius: 20px;
  padding: 4px 12px 4px 8px;
  font-size: .8rem;
  text-decoration: none;
  color: var(--primary);
  font-weight: 500;
  transition: background .15s;
  animation: fadeIn .3s ease;
}
.related-card:hover { background: #e8f0fe; }
.related-card img {
  width: 24px;
  height: 16px;
  object-fit: cover;
  border-radius: 2px;
}

@keyframes fadeIn { from { opacity:0; transform:translateY(4px); } to { opacity:1; transform:none; } }

/* 메시지 목록 */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.msg {
  max-width: 88%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: .88rem;
  line-height: 1.5;
  animation: fadeIn .25s ease;
}
.msg.user {
  background: var(--ball-navy);
  color: #fff;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
  border: 1px solid rgba(232,160,32,.3);
}
.msg.ai {
  background: #f1f3f4;
  color: var(--text);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}
.msg.ai a { color: var(--primary); text-decoration: underline; }
.msg.typing { opacity: .6; }
.msg .dots::after {
  content: '...';
  animation: dots 1.2s steps(4, end) infinite;
}
@keyframes dots {
  0%,20%  { content: '.'; }
  40%     { content: '..'; }
  60%,100%{ content: '...'; }
}

/* 컨텍스트 배지 */
.context-badge {
  font-size: .75rem;
  background: #e8f0fe;
  color: var(--primary);
  padding: 4px 10px;
  border-radius: 10px;
  margin: 0 14px 8px;
  align-self: flex-start;
  flex-shrink: 0;
}

/* 입력 영역 */
.chat-input-area {
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  flex-shrink: 0;
  background: var(--surface);
}
.chat-input-area textarea {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: .88rem;
  resize: none;
  height: 42px;
  max-height: 120px;
  font-family: inherit;
  outline: none;
  transition: border-color .2s;
  overflow: hidden;
}
.chat-input-area textarea:focus { border-color: var(--primary); }
.chat-input-area button {
  padding: 8px 14px;
  background: var(--ball-navy);
  color: var(--ball-gold);
  border: 1.5px solid var(--ball-gold);
  border-radius: 10px;
  cursor: pointer;
  font-size: 1.1rem;
  transition: background .2s, color .2s;
  align-self: flex-end;
  height: 42px;
}
.chat-input-area button:hover { background: var(--ball-gold); color: var(--ball-navy); }
.chat-input-area button:hover { opacity: .85; }
.chat-input-area button:disabled { opacity: .4; cursor: not-allowed; }

/* 빠른 질문 칩 */
.quick-chips {
  padding: 0 14px 10px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  flex-shrink: 0;
}
.chip {
  font-size: .75rem;
  background: #f1f3f4;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 4px 10px;
  cursor: pointer;
  color: var(--text);
  transition: background .15s;
}
.chip:hover { background: #e8f0fe; color: var(--primary); border-color: var(--primary); }

/* ── 반응형 ── */
@media (max-width: 900px) {
  .chat-panel { width: 100%; }
}
@media (max-width: 768px) {
  aside { display: none; }
  main { padding: 20px; }
  .home-hero .stats { gap: 20px; }
}
