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

:root {
  --sidebar-w: 320px;
  --header-h: 56px;
  --bg: #F8FAFC;
  --surface: #FFFFFF;
  --border: #E2E8F0;
  --text: #1E293B;
  --text-muted: #64748B;
  --accent: #3B82F6;
}

html, body { height: 100%; font-family: 'Noto Sans KR', sans-serif; color: var(--text); background: var(--bg); }

/* ── Header ── */
#header {
  position: fixed; top: 0; left: 0; right: 0; z-index: 900;
  height: var(--header-h);
  background: linear-gradient(135deg, #1E3A5F 0%, #2563EB 100%);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.2);
}
#header h1 { color: #fff; font-size: 1.1rem; font-weight: 700; }
#header .header-sub { color: #93C5FD; font-size: 0.78rem; }

/* ── Layout ── */
#layout {
  display: flex;
  position: fixed;
  top: var(--header-h); left: 0; right: 0; bottom: 0;
}

/* ── Sidebar ── */
#sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow: hidden;
}

#day-tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  padding: 8px;
  background: #F1F5F9;
  border-bottom: 1px solid var(--border);
}
.day-tab {
  padding: 6px 4px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  transition: all 0.15s;
  color: var(--text-muted);
}
.day-tab:hover { border-color: var(--accent); color: var(--accent); }
.day-tab.active { color: #fff; border-color: transparent; }

#btn-show-all {
  grid-column: span 4;
  padding: 6px;
  border: 1px dashed var(--border);
  border-radius: 6px;
  background: transparent;
  font-size: 0.72rem;
  cursor: pointer;
  color: var(--text-muted);
  transition: all 0.15s;
}
#btn-show-all:hover { background: #EFF6FF; color: var(--accent); }

#day-detail {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}
#day-detail::-webkit-scrollbar { width: 4px; }
#day-detail::-webkit-scrollbar-track { background: transparent; }
#day-detail::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ── Detail Panel ── */
.detail-header { padding: 10px 12px; background: #F8FAFC; border-radius: 8px; margin-bottom: 12px; }
.detail-day-badge {
  display: inline-block; color: #fff; font-size: 0.68rem;
  padding: 2px 8px; border-radius: 20px; font-weight: 700; margin-bottom: 4px;
}
.detail-header h3 { font-size: 0.95rem; margin-bottom: 2px; }
.detail-subtitle { color: var(--text-muted); font-size: 0.78rem; margin-bottom: 6px; }
.detail-meta { display: flex; gap: 12px; font-size: 0.72rem; color: var(--text-muted); flex-wrap: wrap; }

/* ── Stop List ── */
.stop-list { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.stop-item {
  display: flex; gap: 8px; align-items: flex-start;
  padding: 10px; border-radius: 8px; border: 1px solid var(--border);
  cursor: pointer; transition: all 0.15s; background: var(--surface);
}
.stop-item:hover { background: #EFF6FF; border-color: var(--accent); transform: translateX(2px); }
.stop-turning { background: #FFF7ED; border-color: #FCD34D; }
.stop-hotel { background: #F5F3FF; }
.stop-icon { font-size: 1.3rem; flex-shrink: 0; margin-top: 1px; }
.stop-info strong { font-size: 0.85rem; display: block; margin-bottom: 2px; }
.stop-dur { font-size: 0.72rem; color: var(--text-muted); }
.stop-info p { font-size: 0.75rem; color: var(--text-muted); margin-top: 2px; line-height: 1.4; }
.stop-tip { font-size: 0.72rem; color: #059669; margin-top: 2px; }

/* ── Overview ── */
.overview h3 { font-size: 1rem; margin-bottom: 8px; }
.overview-summary { font-size: 0.82rem; color: var(--text-muted); margin-bottom: 12px; line-height: 1.5; }
.overview-days { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.overview-day-row {
  padding: 6px 10px; border-radius: 4px; background: #F8FAFC;
  display: flex; gap: 8px; align-items: center; font-size: 0.78rem;
}
.overview-day-row strong { font-size: 0.75rem; white-space: nowrap; }
.overview-tips h4 { font-size: 0.85rem; margin-bottom: 6px; }
.overview-tips ul { list-style: disc; padding-left: 16px; }
.overview-tips li { font-size: 0.75rem; color: var(--text-muted); margin-bottom: 4px; line-height: 1.4; }

/* ── Map ── */
#map { flex: 1; z-index: 0; }

/* ── Map Popup ── */
.popup-content { font-family: 'Noto Sans KR', sans-serif; min-width: 200px; }
.popup-header { display: flex; flex-direction: column; gap: 4px; margin-bottom: 6px; }
.popup-header strong { font-size: 0.9rem; }
.popup-badge {
  display: inline-block; padding: 2px 8px; border-radius: 20px;
  font-size: 0.68rem; font-weight: 700; color: #fff; width: fit-content;
}
.popup-badge.turning { background: #F59E0B; }
.popup-badge.hotel { background: #6366F1; }
.popup-badge.home { background: #22C55E; }
.popup-badge.day { /* color set inline */ }
.popup-meta { font-size: 0.75rem; color: #64748B; margin-bottom: 4px; }
.popup-desc { font-size: 0.8rem; line-height: 1.5; color: #1E293B; margin-bottom: 6px; }
.popup-tip { font-size: 0.75rem; color: #059669; padding: 6px 8px; background: #F0FDF4; border-radius: 6px; }

/* ── Chat Widget ── */
#chat-widget {
  position: fixed; bottom: 24px; right: 24px; z-index: 1000;
}

#chat-toggle {
  width: 52px; height: 52px; border-radius: 50%;
  background: linear-gradient(135deg, #2563EB, #7C3AED);
  border: none; cursor: pointer; font-size: 1.4rem;
  box-shadow: 0 4px 16px rgba(37,99,235,0.4);
  transition: transform 0.2s, box-shadow 0.2s;
  display: flex; align-items: center; justify-content: center;
}
#chat-toggle:hover { transform: scale(1.08); box-shadow: 0 6px 20px rgba(37,99,235,0.5); }

#chat-panel {
  position: absolute; bottom: 64px; right: 0;
  width: 340px; max-height: 500px;
  background: var(--surface);
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.15);
  display: flex; flex-direction: column;
  opacity: 0; pointer-events: none; transform: translateY(12px) scale(0.97);
  transition: opacity 0.2s, transform 0.2s;
  overflow: hidden;
}
#chat-panel.open { opacity: 1; pointer-events: all; transform: translateY(0) scale(1); }

#chat-header {
  padding: 12px 16px;
  background: linear-gradient(135deg, #1E3A5F, #2563EB);
  color: #fff;
  display: flex; justify-content: space-between; align-items: center;
  font-size: 0.9rem; font-weight: 700;
}
#chat-header small { color: #93C5FD; font-size: 0.7rem; font-weight: 400; }

#chat-messages {
  flex: 1; overflow-y: auto; padding: 12px;
  display: flex; flex-direction: column; gap: 8px;
  min-height: 0;
}
#chat-messages::-webkit-scrollbar { width: 3px; }
#chat-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.msg { display: flex; }
.msg.user { justify-content: flex-end; }
.msg.assistant { justify-content: flex-start; }
.bubble {
  max-width: 85%; padding: 8px 12px;
  border-radius: 12px; font-size: 0.82rem; line-height: 1.5;
}
.msg.user .bubble { background: #2563EB; color: #fff; border-radius: 12px 12px 2px 12px; }
.msg.assistant .bubble { background: #F1F5F9; color: var(--text); border-radius: 12px 12px 12px 2px; }

.thinking { display: flex; gap: 4px; align-items: center; padding: 12px; }
.thinking span {
  width: 7px; height: 7px; background: #94A3B8;
  border-radius: 50%; animation: bounce 1.2s infinite;
}
.thinking span:nth-child(2) { animation-delay: 0.2s; }
.thinking span:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce { 0%,80%,100% { transform: translateY(0); } 40% { transform: translateY(-6px); } }

#chat-suggestions {
  padding: 8px 12px 0;
  display: flex; flex-wrap: wrap; gap: 6px;
}
.suggestion {
  padding: 4px 10px; border: 1px solid #BFDBFE;
  border-radius: 20px; background: #EFF6FF; color: var(--accent);
  font-size: 0.73rem; cursor: pointer; transition: all 0.15s;
}
.suggestion:hover { background: #DBEAFE; }

#chat-input-row {
  display: flex; gap: 8px; padding: 10px 12px;
  border-top: 1px solid var(--border); align-items: flex-end;
}
#chat-input {
  flex: 1; border: 1px solid var(--border); border-radius: 8px;
  padding: 7px 10px; font-size: 0.82rem; resize: none;
  font-family: inherit; outline: none; transition: border-color 0.15s;
  line-height: 1.4;
}
#chat-input:focus { border-color: var(--accent); }
#chat-send {
  padding: 7px 14px; background: var(--accent); color: #fff;
  border: none; border-radius: 8px; cursor: pointer;
  font-size: 0.8rem; font-weight: 600; white-space: nowrap;
  transition: background 0.15s;
}
#chat-send:hover { background: #1D4ED8; }

/* ── Responsive ── */
@media (max-width: 768px) {
  #sidebar { width: 100%; max-width: 100%; position: absolute; bottom: 0; height: 40%; z-index: 50; }
  #layout { flex-direction: column; }
  #map { flex: 1; }
  #chat-panel { width: calc(100vw - 48px); right: 0; }
}

/* ── Legend ── */
#legend {
  position: absolute; bottom: 16px; left: 8px; z-index: 500;
  background: rgba(255,255,255,0.95); border-radius: 10px;
  padding: 10px 14px; box-shadow: 0 2px 12px rgba(0,0,0,0.12);
  font-size: 0.72rem;
}
#legend h4 { font-size: 0.75rem; margin-bottom: 6px; color: var(--text-muted); }
.legend-item { display: flex; align-items: center; gap: 6px; margin-bottom: 3px; }
.legend-dot {
  width: 12px; height: 12px; border-radius: 50%;
  flex-shrink: 0; border: 2px solid rgba(0,0,0,0.1);
}
