/* ============================================================
   CHINA COMPASS — Layout
   Container, Grid, Navigation, Footer, Responsive
   ============================================================ */

/* ---------- Container ---------- */
.container {
  width: 100%;
  max-width: var(--container-xl);
  margin: 0 auto;
  padding: 0 var(--space-5);
}

.container-narrow { max-width: var(--container-lg); }
.container-wide   { max-width: var(--container-2xl); }

/* ---------- Grid System ---------- */
.grid {
  display: grid;
  gap: var(--space-5);
}

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

.grid-sidebar {
  grid-template-columns: 1fr 320px;
  gap: var(--space-8);
}

.grid-sidebar-left {
  grid-template-columns: 220px 1fr;
  gap: var(--space-6);
}

/* ---------- Flex Utilities ---------- */
.flex     { display: flex; }
.flex-col { flex-direction: column; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.gap-5 { gap: var(--space-5); }
.gap-6 { gap: var(--space-6); }

/* ---------- Section Spacing ---------- */
.section {
  padding: var(--space-10) 0;
}

.section + .section {
  border-top: 1px solid var(--border-light);
}

/* ---------- Navigation ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--nav-bg);
  border-bottom: 1px solid var(--nav-border);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  overflow: visible;
}

.site-header__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
  max-width: var(--container-xl);
  margin: 0 auto;
  padding: 0 var(--space-5);
}

.site-logo {
  font-size: var(--text-lg);
  font-weight: var(--weight-bold);
  color: var(--text-primary);
  text-decoration: none;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 6px;
}

.site-logo:hover {
  text-decoration: none;
  color: var(--accent);
}

.site-logo__icon {
  width: 44px;
  height: auto;
  filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.4));
}

.site-logo:hover .site-logo__icon {
  filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.5));
}

.site-logo__text {
  color: inherit;
  font-size: var(--text-base);
  font-weight: var(--weight-bold);
  letter-spacing: 0.5px;
}

.site-logo__mark { color: var(--accent); }

/* Main nav */
.main-nav {
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.main-nav__link {
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--text-muted);
  text-decoration: none;
  border-radius: var(--radius-sm);
  transition: color var(--transition-fast), background var(--transition-fast);
  white-space: nowrap;
}

.main-nav__link:hover {
  color: var(--text-primary);
  background: var(--bg-tertiary);
  text-decoration: none;
}

.main-nav__link[aria-current="page"],
.main-nav__link.active {
  color: var(--accent);
  font-weight: var(--weight-semibold);
}

/* Header actions */
.header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.lang-toggle {
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--text-muted);
  text-decoration: none;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
  min-height: 44px;
  min-width: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.lang-toggle:hover {
  color: var(--accent);
  border-color: var(--accent);
  text-decoration: none;
}

.theme-toggle {
  background: none;
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-sm);
  padding: var(--space-1) var(--space-2);
  cursor: pointer;
  color: var(--text-muted);
  font-size: var(--text-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  transition: all var(--transition-fast);
}

.theme-toggle:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.theme-toggle .icon-sun,
.theme-toggle .icon-moon { display: none; }

[data-theme="light"] .theme-toggle .icon-sun { display: block; }
[data-theme="light"] .theme-toggle .icon-moon { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun { display: none; }
[data-theme="dark"] .theme-toggle .icon-moon { display: block; }

/* Both shown in dark-only mode (since we force dark) */
.theme-toggle .icon-moon { display: block; }

/* ---------- Mobile Hamburger ---------- */
.hamburger-toggle { display: none; }

.hamburger-label {
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  width: 44px;
  height: 44px;
  cursor: pointer;
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-sm);
}

.hamburger-label span,
.hamburger-label span::before,
.hamburger-label span::after {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--text-secondary);
  position: relative;
  transition: all var(--transition-fast);
}

.hamburger-label span::before,
.hamburger-label span::after {
  content: '';
  position: absolute;
}

.hamburger-label span::before { top: -6px; }
.hamburger-label span::after  { top: 6px; }

.hamburger-toggle:checked + .hamburger-label span { background: transparent; }
.hamburger-toggle:checked + .hamburger-label span::before { top: 0; transform: rotate(45deg); }
.hamburger-toggle:checked + .hamburger-label span::after  { top: 0; transform: rotate(-45deg); }

/* ---------- Footer ---------- */
.site-footer {
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-light);
  padding: var(--space-8) 0;
  margin-top: var(--space-12);
}

.site-footer__inner {
  max-width: var(--container-xl);
  margin: 0 auto;
  padding: 0 var(--space-5);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: var(--space-8);
}

.footer-section { flex: 1; min-width: 180px; }
.footer-section__title {
  font-size: var(--text-sm);
  font-weight: var(--weight-bold);
  color: var(--text-primary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: var(--space-3);
}

.footer-section__list { list-style: none; padding: 0; margin: 0; }
.footer-section__list li { margin-bottom: var(--space-2); }
.footer-section__list a { font-size: var(--text-sm); color: var(--text-muted); }
.footer-section__list a:hover { color: var(--accent); }

.footer-powered {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  padding-top: var(--space-5);
  margin-top: var(--space-5);
  border-top: 1px solid var(--border-light);
}

.footer-powered__text { font-size: var(--text-sm); color: var(--text-muted); }
.footer-powered__logo { height: 60px; width: auto; }
.footer-powered__name { font-size: var(--text-base); font-weight: var(--weight-semibold); color: var(--text-primary); }

.site-footer__bottom {
  width: 100%;
  padding-top: var(--space-3);
  text-align: center;
  font-size: var(--text-sm);
  color: var(--text-muted);
}

/* ---------- Main Content Area ---------- */
.main-content {
  min-height: calc(100vh - 64px - 200px);
}

/* ---------- Responsive: Tablet (768px) ---------- */
@media (max-width: 768px) {
  .site-logo__icon {
    width: 36px;
  }

  .container {
    padding: 0 var(--space-4);
  }

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

  h1 { font-size: var(--text-3xl); }
  h2 { font-size: var(--text-2xl); }
  h3 { font-size: var(--text-xl); }

  .section { padding: var(--space-6) 0; }

  .site-header__inner { height: 56px; }

  .hamburger-label { display: flex; }

  .main-nav {
    display: none;
    position: absolute;
    top: 56px;
    left: 0;
    right: 0;
    background: var(--nav-bg);
    border-bottom: 1px solid var(--nav-border);
    flex-direction: column;
    padding: var(--space-4);
    box-shadow: var(--shadow-lg);
    z-index: 99;
    max-height: calc(100vh - 56px);
    overflow-y: auto;
    backdrop-filter: blur(12px);
  }

  .hamburger-toggle:checked ~ .main-nav { display: flex; }

  .main-nav__link {
    padding: var(--space-3) var(--space-4);
    width: 100%;
    min-height: 44px;
    display: flex;
    align-items: center;
  }

  .hero-strip { padding: var(--space-6) 0; }
  .hero-strip__title { font-size: var(--text-2xl); }

  .site-footer__inner {
    flex-direction: column;
    gap: var(--space-5);
  }

  .footer-section { min-width: 0; width: 100%; }

  /* Category sidebar becomes horizontal scroll on tablet/mobile */
  .category-sidebar {
    position: static;
    margin-bottom: var(--space-4);
  }

  .category-sidebar__list {
    display: flex;
    gap: var(--space-2);
    overflow-x: auto;
    padding-bottom: var(--space-2);
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    scroll-snap-type: x proximity;
  }

  .category-sidebar__list::-webkit-scrollbar {
    display: none;
  }

  .category-sidebar__item {
    border-left: none;
    border-bottom: 2px solid transparent;
    border-radius: var(--radius-sm);
    padding: var(--space-2) var(--space-4);
    white-space: nowrap;
    min-height: 44px;
    min-width: 44px;
    justify-content: center;
    width: auto;
    flex-shrink: 0;
    scroll-snap-align: start;
  }

  .category-sidebar__item.active {
    border-bottom-color: var(--accent);
    border-left-color: transparent;
    background: var(--accent-light);
    font-weight: var(--weight-semibold);
  }

  .category-sidebar__section {
    margin-top: var(--space-3);
  }

  .grid { gap: var(--space-4); }
}

/* ---------- Responsive: Small Mobile (480px) ---------- */
@media (max-width: 480px) {
  .site-logo__icon {
    width: 30px;
  }

  .grid-4 { grid-template-columns: 1fr; }

  .container { padding: 0 var(--space-4); }

  h1 { font-size: var(--text-2xl); }

  .stat-card__value { font-size: var(--text-2xl); }
  .tension-display__score { font-size: 3rem; }

  .site-header__inner { height: 52px; }

  .grid { gap: var(--space-3); }

  .section { padding: var(--space-4) 0; }

  .site-footer {
    padding: var(--space-5) 0;
    margin-top: var(--space-8);
  }

  .main-nav {
    max-height: calc(100vh - 48px);
    top: 48px;
  }

  .signal-card--hero .signal-card__title {
    font-size: var(--text-xl);
  }
}

/* ---------- Responsive: Very Small Mobile (320px) ---------- */
@media (max-width: 320px) {
  .container { padding: 0 var(--space-3); }
  h1 { font-size: var(--text-xl); }
  .hero-strip__title { font-size: var(--text-xl); }
  .hero-strip__subtitle { font-size: var(--text-sm); }
  .stat-card__value { font-size: var(--text-xl); }
  .site-logo__text { font-size: var(--text-sm); }
  .cta-form { flex-direction: column; }
  .cta-form__input { width: 100%; }
}

/* ---------- Tablet Landscape (1024px) ---------- */
@media (min-width: 769px) and (max-width: 1024px) {
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-sidebar { grid-template-columns: 1fr 280px; }
}

/* ---------- Sidebar-left collapse (≤1024px) ---------- */
@media (max-width: 1024px) {
  .grid-sidebar-left {
    grid-template-columns: 1fr;
    gap: var(--space-5);
  }
  .grid-sidebar-left > aside {
    order: 2;
    position: static;
  }
  .grid-sidebar-left > div {
    order: 1;
  }
  .grid-sidebar-left > * {
    min-width: 0;
    max-width: 100%;
  }
  .grid-sidebar-left .cta-box,
  .grid-sidebar-left .cta-form,
  .grid-sidebar-left .cta-form__input {
    max-width: 100%;
    width: 100%;
  }
  .cta-form__input {
    min-width: 0;
  }
}

/* ---------- Desktop: 1024px+ ---------- */
@media (min-width: 1024px) {
  .grid-3-tablet { grid-template-columns: repeat(3, 1fr); }
}

/* ---------- Large Desktop: 1440px+ ---------- */
@media (min-width: 1440px) {
  .container { padding: 0 var(--space-8); }
}

/* ---------- Print ---------- */
@media print {
  .site-header,
  .site-footer,
  .theme-toggle,
  .lang-toggle,
  .hamburger-label,
  .filter-bar,
  .category-sidebar {
    display: none !important;
  }

  body {
    background: white;
    color: black;
  }

  .card, .signal-card, .stat-card {
    box-shadow: none;
    border: 1px solid #ccc;
  }

  .signal-card {
    min-height: auto;
  }

  .signal-card__overlay {
    background: none !important;
  }

  .signal-card__title,
  .signal-card__summary {
    color: black;
  }
}

/* ---------- S14: Global 44px touch target floor (mobile) ---------- */
@media (max-width: 768px) {
  button,
  [role="button"],
  input[type="button"],
  input[type="submit"],
  input[type="reset"] {
    min-height: 44px;
  }

  .main-nav__link,
  .footer-section__list a,
  .breadcrumb a,
  .site-logo,
  .toc__link,
  .section-header__link {
    min-height: 44px;
    min-width: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: flex-start;
  }

  .signal-card__source-link a {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
  }

  .filter-pill,
  .category-sidebar__item {
    min-height: 44px;
    min-width: 44px;
  }

  /* Container-narrow inline prose links (about page, etc.) */
  .container-narrow p a,
  .container-narrow li a {
    padding: 6px 0;
    display: inline-block;
  }

  /* Social card "view original" link — expand tap area */
  .social-card__time {
    min-height: 32px;
    padding: 4px 8px;
    display: inline-flex;
    align-items: center;
  }

  /* FDI/M&A source arrow link — expand tap area */
  .data-table td a {
    min-height: 32px;
    min-width: 32px;
    padding: 4px 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .card-link,
  .signal-card-link,
  .entity-card {
    min-height: 44px;
  }

  .long-form p a,
  .long-form li a,
  .signal-card__source-link a {
    padding: 4px 0;
  }

  .badge,
  .badge-category,
  .badge-severity {
    min-height: 28px;
    display: inline-flex;
    align-items: center;
  }
}
