/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, sans-serif;
  color: #1a1a1a;
  background: #fafafa;
  line-height: 1.6;
  display: flex;
  min-height: 100vh;
}
a { color: #2563eb; text-decoration: none; }
a:hover { text-decoration: underline; }

/* === Sidebar === */
.sidebar {
  width: 280px;
  min-width: 280px;
  background: #fff;
  border-right: 1px solid #e5e7eb;
  padding: 1.5rem 0;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  overflow-y: auto;
  z-index: 100;
  transition: transform .25s ease;
}
.sidebar-header {
  padding: 0 1.25rem 1.25rem;
  border-bottom: 1px solid #e5e7eb;
  margin-bottom: .75rem;
}
.sidebar-header .logo {
  font-size: 1.15rem;
  font-weight: 700;
  color: #1a1a1a;
  display: block;
  line-height: 1.3;
}
.sidebar-header .logo span { display: block; font-size: .8rem; font-weight: 400; color: #6b7280; }
.sidebar nav ul { list-style: none; }
.sidebar nav > ul > li > a,
.sidebar nav > ul > li > span {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .5rem 1.25rem;
  color: #374151;
  font-size: .9rem;
  cursor: pointer;
  transition: background .15s, color .15s;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}
.sidebar nav > ul > li > a:hover,
.sidebar nav > ul > li > span:hover {
  background: #f3f4f6;
  color: #111;
  text-decoration: none;
}
.sidebar nav > ul > li > a.active {
  background: #eff6ff;
  color: #2563eb;
  font-weight: 600;
}
.sidebar .nav-icon { font-size: 1rem; width: 1.5rem; text-align: center; flex-shrink: 0; }

/* Nested nav children — collapsible */
.nav-children {
  padding-left: 1rem;
  max-height: 0;
  overflow: hidden;
  transition: max-height .25s ease;
}
.nav-children.open {
  max-height: 80rem;
}
.nav-children a {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .35rem 1.25rem .35rem 2rem;
  color: #6b7280;
  font-size: .85rem;
  transition: background .15s, color .15s;
  text-decoration: none;
}
.nav-children a:hover { background: #f3f4f6; color: #111; }
.nav-children a.active { background: #eff6ff; color: #2563eb; font-weight: 600; }

/* Toggle arrow */
.nav-toggle {
  margin-left: auto;
  font-size: .7rem;
  color: #9ca3af;
  transition: transform .2s ease;
  cursor: pointer;
  padding: 0 .25rem;
}
.nav-toggle.open {
  transform: rotate(90deg);
}

/* Loading state */
.loading { padding: 2rem; color: #6b7280; }

/* === Mobile toggle === */
.menu-toggle {
  display: none;
  position: fixed;
  top: .75rem;
  left: .75rem;
  z-index: 200;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: .5rem;
  padding: .5rem .65rem;
  font-size: 1.25rem;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
}
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.3);
  z-index: 90;
}

/* === Main Content === */
.main {
  margin-left: 280px;
  flex: 1;
  min-width: 0;
  padding: 2.5rem 3rem;
  max-width: 900px;
}
.main h1 {
  font-size: 1.75rem;
  font-weight: 700;
  margin-bottom: .5rem;
  color: #111;
}
.main .subtitle {
  color: #6b7280;
  margin-bottom: 2rem;
  font-size: .95rem;
}
.main h2 {
  font-size: 1.25rem;
  font-weight: 600;
  margin: 2rem 0 .75rem;
  color: #111;
}
.main p, .main li { font-size: .95rem; color: #374151; }
.main ul, .main ol { padding-left: 1.5rem; margin-bottom: 1rem; }
.main li { margin-bottom: .35rem; }

/* === Tile Grid === */
.tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}
.tile {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: .75rem;
  padding: 1.25rem;
  text-align: center;
  transition: box-shadow .2s, transform .15s;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .5rem;
}
.tile:hover {
  box-shadow: 0 4px 12px rgba(0,0,0,.08);
  transform: translateY(-2px);
  text-decoration: none;
}
.tile .tile-icon { font-size: 2rem; }
.tile .tile-label {
  font-size: .9rem;
  font-weight: 500;
  color: #1a1a1a;
  line-height: 1.3;
}
.tile .tile-desc {
  font-size: .78rem;
  color: #6b7280;
  line-height: 1.4;
}

/* === Detail page === */
.detail-back {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  font-size: .85rem;
  color: #6b7280;
  margin-bottom: 1.5rem;
}
.detail-back:hover { color: #2563eb; text-decoration: none; }

/* === Chat === */
.chat-container {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: .75rem;
  overflow: hidden;
  margin-top: 1rem;
  display: flex;
  flex-direction: column;
  height: calc(100vh - 12rem);
  min-height: 400px;
}
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: .75rem;
}
.chat-bubble {
  max-width: 80%;
  padding: .75rem 1rem;
  border-radius: 1rem;
  font-size: .9rem;
  line-height: 1.5;
  word-wrap: break-word;
}
.chat-bubble.user {
  align-self: flex-end;
  background: #2563eb;
  color: #fff;
  border-bottom-right-radius: .25rem;
}
.chat-bubble.assistant {
  align-self: flex-start;
  background: #f3f4f6;
  color: #1a1a1a;
  border-bottom-left-radius: .25rem;
}
.chat-input-area {
  display: flex;
  border-top: 1px solid #e5e7eb;
  padding: .75rem;
  gap: .5rem;
}
.chat-input-area input {
  flex: 1;
  border: 1px solid #e5e7eb;
  border-radius: .5rem;
  padding: .6rem .85rem;
  font-size: .9rem;
  outline: none;
}
.chat-input-area input:focus { border-color: #2563eb; }
.chat-input-area button {
  background: #2563eb;
  color: #fff;
  border: none;
  border-radius: .5rem;
  padding: .6rem 1rem;
  font-size: 1rem;
  cursor: pointer;
}
.chat-input-area button:hover { background: #1d4ed8; }

/* === Quick-facts box === */
.facts-box {
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: .75rem;
  padding: 1.25rem;
  margin: 1.5rem 0;
}
.facts-box h3 { font-size: .95rem; margin-bottom: .5rem; }

/* === Page Chat Bar === */
.page-chat { border-top: 2px solid #e2e8f0; margin-top: 2rem; }
.page-chat-toggle {
  display: flex; align-items: center; gap: .5rem;
  padding: .75rem 0; cursor: pointer; user-select: none;
  font-weight: 600; font-size: .95rem; color: #475569;
}
.page-chat-toggle:hover { color: #1e293b; }
.page-chat-arrow {
  display: inline-block; transition: transform .2s;
  font-size: .75rem;
}
.page-chat-arrow.open { transform: rotate(90deg); }
.page-chat-body {
  max-height: 0; overflow: hidden; transition: max-height .3s ease;
}
.page-chat-body.open { max-height: 600px; overflow: visible; }
.page-chat-messages {
  max-height: 300px; overflow-y: auto;
  padding: .5rem 0; display: flex; flex-direction: column; gap: .5rem;
}
.page-chat-messages .chat-bubble {
  padding: .6rem .9rem; border-radius: .75rem; max-width: 85%;
  font-size: .9rem; line-height: 1.45; word-wrap: break-word;
}
.page-chat-messages .chat-bubble.user {
  align-self: flex-end; background: #3b82f6; color: #fff;
}
.page-chat-messages .chat-bubble.assistant {
  align-self: flex-start; background: #f1f5f9; color: #1e293b;
}
.page-chat-messages .chat-bubble.system {
  align-self: center; background: #ecfdf5; color: #065f46; font-size: .85rem;
}
.page-chat-input-row {
  display: flex; gap: .5rem; margin-top: .5rem;
}
.page-chat-input-row input {
  flex: 1; padding: .6rem .75rem; border: 1px solid #cbd5e1;
  border-radius: .5rem; font-size: .9rem; outline: none;
}
.page-chat-input-row input:focus { border-color: #3b82f6; }
.page-chat-input-row button {
  padding: .6rem 1rem; background: #3b82f6; color: #fff;
  border: none; border-radius: .5rem; cursor: pointer; font-size: .9rem;
}
.page-chat-input-row button:hover { background: #2563eb; }

/* === Responsive === */
@media (max-width: 768px) {
  .menu-toggle { display: block; }
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.open { display: block; }
  .main { margin-left: 0; padding: 1.25rem 1rem; padding-top: 3.5rem; }
  .tile-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
}
