/* =========================================================
   乡技传承 · 桂冀土专家数字档案与技术赋能服务平台
   Global stylesheet — warm rural palette, light theme only.
   ========================================================= */

/* ---------- 1. Design tokens ---------- */
:root {
  --bg-page: #F5F1E8;          /* warm beige page background */
  --bg-card: #FFFEF9;          /* off-white card */
  --primary: #2D6A4F;          /* deep green: navbar, primary button, headings */
  --primary-dark: #1B4332;     /* primary hover */
  --primary-light: #52B788;    /* secondary button / hover */
  --accent-blue: #457B9D;      /* Guangxi data, 2nd chart series */
  --accent-orange: #E76F51;    /* Hebei data, gap warning */
  --success: #6A994E;
  --text-main: #2B2D42;        /* body text (not pure black) */
  --text-muted: #6C757D;       /* secondary text */
  --border: #DEE2E6;
  --footer-bg: #EDE8DF;
  --radius: 12px;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
  --shadow-hover: 0 8px 24px rgba(0, 0, 0, 0.12);
  --transition: all 0.3s ease;
  --navbar-h: 64px;
}

/* ---------- 2. Reset & base ---------- */
* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg-page);
  color: var(--text-main);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
  margin: 0 0 12px;
  color: var(--primary);
  font-weight: 700;
  line-height: 1.35;
}

h1 { font-size: 24px; }
h2 { font-size: 20px; }
h3 { font-size: 17px; }

p {
  margin: 0 0 12px;
  font-size: 14px;
}

a {
  color: var(--primary);
  text-decoration: none;
  transition: var(--transition);
}

a:hover {
  color: var(--primary-light);
}

button {
  font-family: inherit;
  font-size: 14px;
}

/* ---------- 3. Navbar ---------- */
.navbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  height: var(--navbar-h);
  background: var(--primary);
  color: #fff;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.10);
}

.navbar-inner {
  height: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-icon {
  font-size: 22px;
  line-height: 1;
}

.brand-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.brand-title {
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.5px;
  line-height: 1.25;
  white-space: nowrap;
}

.brand-sub {
  font-size: 12px;
  color: #fff;
  opacity: 0.8;
  line-height: 1.25;
  white-space: nowrap;
}

.nav {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
}

.nav-btn {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: rgba(255, 255, 255, 0.8);
  padding: 8px 16px;
  cursor: pointer;
  white-space: nowrap;
  transition: var(--transition);
}

.nav-btn:hover {
  color: #fff;
}

.nav-btn.active {
  color: #fff;
  font-weight: bold;
  border-bottom: 2px solid #fff;
}

/* ---------- 4. Page sections & layout ---------- */
.page-section {
  display: none;
  padding-top: calc(var(--navbar-h) + 16px);   /* clear the fixed navbar */
  padding-bottom: 40px;
  min-height: calc(100vh - var(--navbar-h) - 72px);
}

.page-section.active-section {
  display: block;
  animation: sectionFadeIn 0.3s ease;
}

@keyframes sectionFadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding-left: 24px;
  padding-right: 24px;
}

.page-title {
  margin-bottom: 6px;
}

.page-desc {
  color: var(--text-muted);
  margin: 0;
}

/* Page header block: 28px title + muted subtitle (padding: 32px 0 24px) */
.page-head {
  padding: 32px 0 24px;
}

.page-head h1 {
  font-size: 28px;
  font-weight: 700;
  color: var(--primary);
  margin: 0 0 8px;
}

.page-head .page-sub {
  font-size: 14px;
  color: var(--text-muted);
  margin: 0;
}

/* ---------- 5. Card ---------- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 20px;
  transition: var(--transition);
}

.card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-hover);
}

/* Static card: keeps the surface look without the lift (dashboard panels) */
.card-static:hover {
  transform: none;
  box-shadow: var(--shadow);
}

/* Card section title with a 3px deep-green bar on the left */
.block-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--primary);
  margin: 0 0 16px;
  padding-left: 10px;
  border-left: 3px solid var(--primary);
  line-height: 1.4;
}

/* ---------- 6. Buttons ---------- */
.btn-primary {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 10px 20px;
  cursor: pointer;
  transition: var(--transition);
}

.btn-primary:hover {
  background: var(--primary-dark);
}

.btn-secondary {
  background: var(--primary-light);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 10px 20px;
  cursor: pointer;
  transition: var(--transition);
}

.btn-secondary:hover {
  background: var(--primary);
}

/* ---------- 7. Footer ---------- */
.footer {
  background: var(--footer-bg);
  color: var(--text-muted);
  text-align: center;
  font-size: 13px;
  line-height: 1.6;
  padding: 18px 24px;
  margin-top: 20px;
}

/* =========================================================
   9. Home module (#home)
   ========================================================= */

/* --- 9.1 Core row: map (60%) + chain cards (40%) --- */
.core-row {
  display: flex;
  gap: 24px;
  margin-bottom: 32px;
  align-items: stretch;
}

.core-row > .col-map {
  width: 60%;
  flex: none;
}

.core-row > .col-chain {
  width: 40%;
  flex: none;
  display: flex;                 /* lets the right card stretch to full height */
}

.core-row > .col-chain > .card {
  width: 100%;
  display: flex;
  flex-direction: column;
}

/* --- 9.2 Map --- */
.map-card {
  position: relative;
  margin-bottom: 0;
}

.map-box {
  position: relative;
  width: 100%;
  height: 380px;
}

#home-map {
  width: 100%;
  height: 100%;
}

/* Fallback text shown while the GeoJSON is loading or if it fails */
.map-fallback {
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  transform: translateY(-50%);
  margin: 0;
  text-align: center;
  font-size: 14px;
  color: var(--text-muted);
}

/* Small bottom-left legend inside the map card */
.map-legend {
  position: absolute;
  left: 16px;
  bottom: 12px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
}

.map-legend .lg-swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  background: var(--primary);
  opacity: 0.85;
  flex: none;
}

.map-legend .lg-sep {
  opacity: 0.6;
}

/* --- 9.3 Chain cards (three key chains) --- */
.chain-list {
  display: flex;
  flex-direction: column;
}

.chain-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 12px;
  transition: var(--transition);
}

.chain-card:last-child {
  margin-bottom: 0;
}

.chain-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

/* Left accent colour per chain: blue / green / orange */
.chain-card.chain-blue   { border-left-color: var(--accent-blue); }
.chain-card.chain-green  { border-left-color: var(--primary); }
.chain-card.chain-orange { border-left-color: var(--accent-orange); }

.chain-head {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 10px;
}

.chain-flow {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
}

.chain-flow .cf-value {
  font-size: 18px;
  font-weight: 700;
  color: var(--primary);
  line-height: 1.3;
}

.chain-flow .cf-arrow {
  font-size: 15px;
  color: #ADB5BD;
}

.chain-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 8px;
}

.chain-note {
  font-size: 13px;
  color: var(--text-muted);
}

.chain-loss {
  font-size: 13px;
  font-weight: 700;
  color: var(--accent-orange);
  white-space: nowrap;
}

/* --- 9.4 Core conclusion banner --- */
.conclusion {
  background: #E8F5E9;
  border-left: 4px solid var(--primary);
  border-radius: 8px;
  padding: 16px 20px;
  margin-bottom: 32px;
}

.conclusion-text {
  font-size: 15px;
  color: var(--primary);
  font-weight: 700;
  margin: 0;
  line-height: 1.7;
}

.conclusion-sub {
  font-size: 13px;
  color: var(--text-muted);
  margin: 8px 0 0;
  line-height: 1.7;
}

/* --- 9.5 Role guide cards ("我是...") --- */
.guide-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-muted);
  margin: 0 0 12px;
}

.guide-row {
  display: flex;
  gap: 16px;
  margin-bottom: 32px;
}

.guide-card {
  flex: 1 1 0;
  min-width: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  cursor: pointer;
  transition: var(--transition);
}

.guide-card:hover,
.guide-card:focus-visible {
  transform: translateY(-3px);
  border-color: var(--primary);
  box-shadow: var(--shadow-hover);
  outline: none;
}

.guide-icon {
  font-size: 24px;
  line-height: 1.2;
  margin-bottom: 8px;
}

.guide-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 4px;
}

.guide-sub {
  font-size: 13px;
  color: var(--text-muted);
}

.guide-arrow {
  margin-top: 10px;
  text-align: right;
  font-size: 15px;
  color: var(--primary);
  transition: var(--transition);
}

.guide-card:hover .guide-arrow {
  transform: translateX(4px);
}

/* --- 9.6 Feature entry cards (2 x 2 grid) --- */
.feature-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 40px;
}

.feature-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  cursor: pointer;
  transition: var(--transition);
}

.feature-card:hover,
.feature-card:focus-visible {
  transform: translateY(-3px);
  box-shadow: var(--shadow-hover);
  outline: none;
}

.feature-icon {
  font-size: 32px;
  line-height: 1.2;
  margin-bottom: 8px;
}

.feature-name {
  font-size: 18px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 6px;
}

.feature-sub {
  font-size: 14px;
  color: var(--text-muted);
}

.feature-enter {
  margin-top: 12px;
  text-align: right;
  font-size: 14px;
  color: var(--primary);
  font-weight: 700;
  transition: var(--transition);
}

.feature-card:hover .feature-enter {
  transform: translateX(4px);
}

/* =========================================================
   10. Detail module (#detail)
   ========================================================= */

/* --- 10.1 Breadcrumb bar --- */
.breadcrumb-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 24px 0 16px;
}

.breadcrumb {
  font-size: 14px;
  color: var(--text-muted);
}

.crumb-link {
  color: var(--primary);
  cursor: pointer;
  transition: var(--transition);
}

.crumb-link:hover {
  color: var(--primary-light);
  text-decoration: underline;
}

.crumb-sep {
  margin: 0 6px;
  color: var(--text-muted);
}

.crumb-current {
  color: var(--text-main);
  font-weight: 700;
}

.btn-sm {
  padding: 8px 16px;
  font-size: 13px;
}

/* --- 10.2 Two-column layout --- */
.detail-layout {
  display: flex;
  align-items: flex-start;
  gap: 20px;
  padding-bottom: 40px;
}

.filter-panel {
  width: 240px;
  flex: none;
  padding: 16px;
  position: sticky;
  top: 80px;
  margin-bottom: 0;
}

/* Keep the sticky panel anchored on hover (no lift). */
.filter-panel:hover {
  transform: none;
  box-shadow: var(--shadow);
}

.filter-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--primary);
  margin: 0 0 16px;
}

.filter-group {
  margin-bottom: 20px;
}

.filter-group-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 8px;
}

.filter-option {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-main);
  padding: 4px 0;
  cursor: pointer;
  transition: var(--transition);
}

.filter-option:hover {
  color: var(--primary);
}

.filter-option input[type="checkbox"] {
  width: 15px;
  height: 15px;
  margin: 0;
  accent-color: var(--primary);
  cursor: pointer;
}

.btn-ghost {
  background: transparent;
  color: var(--primary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 14px;
  font-size: 13px;
  cursor: pointer;
  transition: var(--transition);
}

.btn-ghost:hover {
  border-color: var(--primary);
  background: #F0F7F2;
}

.filter-panel .btn-ghost {
  width: 100%;
}

.detail-content {
  flex: 1 1 auto;
  min-width: 0;
}

/* --- 10.3 Tabs --- */
.tab-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}

.tab-btn {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 10px 16px;
  font-size: 14px;
  color: var(--text-muted);
  cursor: pointer;
  transition: var(--transition);
}

.tab-btn:hover {
  color: var(--primary);
}

.tab-btn.active {
  color: var(--primary);
  font-weight: 700;
  border-bottom: 2px solid var(--primary);
}

/* --- 10.4 Chart toolbar & filter tags --- */
.chart-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 12px;
}

.chart-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-main);
  margin: 0;
}

.type-switch {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.type-btn {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 14px;
  font-size: 13px;
  color: var(--text-main);
  cursor: pointer;
  transition: var(--transition);
}

.type-btn:hover {
  border-color: var(--primary-light);
  color: var(--primary);
}

.type-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
  min-height: 24px;
}

.tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #F0F7F2;
  border: 1px solid #D6E6DC;
  border-radius: 20px;
  padding: 3px 10px;
  font-size: 12px;
  color: var(--primary);
}

.tag-note {
  background: #FFF6EF;
  border-color: #F6D9CB;
  color: var(--accent-orange);
}

.tag-x {
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  color: var(--text-muted);
  transition: var(--transition);
}

.tag-x:hover {
  color: var(--accent-orange);
}

/* --- 10.5 Chart & insight cards --- */
.chart-card {
  padding: 16px;
  margin-bottom: 20px;
}

.chart-box {
  width: 100%;
  height: 420px;
}

.empty-hint {
  margin: 0;
  padding-top: 180px;
  text-align: center;
  font-size: 14px;
  color: var(--text-muted);
}

.insight {
  background: #E8F5E9;
  border-left: 4px solid var(--primary);
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 20px;
  font-size: 14px;
  color: var(--primary);
  line-height: 1.7;
}

/* --- 10.6 Raw data table --- */
.table-card {
  padding: 16px;
  margin-bottom: 0;
}

.table-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--primary);
  margin: 0 0 12px;
}

.table-scroll {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th {
  background: #F0EDE4;
  color: var(--primary);
  font-weight: 700;
  font-size: 13px;
  text-align: left;
  padding: 10px;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

.data-table th.th-sortable {
  cursor: pointer;
  user-select: none;
  transition: var(--transition);
}

.data-table th.th-sortable:hover {
  background: #E8E5DD;
}

.th-arrow {
  margin-left: 4px;
  font-size: 12px;
}

.data-table td {
  padding: 10px;
  border-bottom: 1px solid var(--border);
  color: var(--text-main);
}

.data-table tbody tr {
  cursor: pointer;
  transition: var(--transition);
}

.data-table tbody tr.stripe {
  background: #FAF8F3;
}

/* Significant rows win over the zebra stripe (declared later). */
.data-table tbody tr.sig-row {
  background: #F0F7F2;
}

.data-table tbody tr:hover {
  background: #F0F7F2;
}

/* Row picked on the chart */
.data-table tbody tr.row-selected {
  border-left: 4px solid var(--primary);
  background: #F0F7F2;
}

.data-table tbody tr.row-selected td:first-child {
  font-weight: 700;
  color: var(--primary);
}

.td-name {
  font-weight: 500;
}

.sig-yes {
  color: var(--accent-orange);
  font-weight: 700;
}

.sig-no {
  color: #ADB5BD;
}

.table-empty {
  text-align: center;
  color: var(--text-muted);
  padding: 24px 10px !important;
}

.table-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 14px;
}

.table-count {
  font-size: 13px;
  color: var(--text-muted);
}

.table-actions {
  display: flex;
  gap: 8px;
}

/* --- 10.7 "即将上线" placeholder --- */
.placeholder {
  text-align: center;
  padding: 60px 20px;
}

.placeholder-icon {
  font-size: 32px;
  margin-bottom: 8px;
}

.placeholder h3 {
  font-size: 16px;
  color: var(--primary);
  margin: 0 0 6px;
}

.placeholder p {
  font-size: 14px;
  color: var(--text-muted);
  margin: 0;
}

/* --- 10.8 Toast feedback --- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 40px;
  transform: translate(-50%, 12px);
  background: #2D6A4F;
  color: #fff;
  font-size: 13px;
  padding: 8px 18px;
  border-radius: 20px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s ease;
  z-index: 2000;
}

.toast.toast-show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------- 10.9 机制分析 module (#detail-panel-mechanism) ---------- */
/* The chart containers of this tab are written directly into index.html;
   these two rules only supply the shared spacing/skin so no inline styling
   is needed for them. */
.mechanism-module {
  background: #FFFEF9;
  border: 1px solid #DEE2E6;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  padding: 16px;
}

.mechanism-module .chart-title {
  font-size: 16px;
  font-weight: 700;
  color: #2D6A4F;
  margin: 0 0 12px;
}

.conclusion-card {
  background: #E8F5E9;
  border-left: 4px solid #2D6A4F;
  border-radius: 8px;
  padding: 14px 18px;
  margin-top: 16px;
  font-size: 14px;
  color: #2D6A4F;
  line-height: 1.7;
}

.conclusion-card:empty {
  display: none;
}

/* ---------- 11. Responsive ---------- */
@media (max-width: 768px) {
  /* The two moderation charts sit side by side on desktop and stack here. */
  #moderation-chart-1,
  #moderation-chart-2 {
    width: 100% !important;
  }

  .navbar-inner {
    padding: 0 12px;
    gap: 8px;
  }

  .brand-sub {
    display: none;           /* keep the 64px bar tidy on small screens */
  }

  .brand-title {
    font-size: 15px;
  }

  .nav-btn {
    padding: 8px 8px;
    font-size: 13px;         /* smaller nav text */
  }

  .container {
    padding-left: 12px;      /* content padding 24px -> 12px */
    padding-right: 12px;
  }

  .card {
    padding: 16px;
  }

  h1 { font-size: 20px; }

  /* ---- Home module stacks on small screens ---- */
  .page-head {
    padding: 24px 0 16px;
  }

  .page-head h1 {
    font-size: 22px;
  }

  /* The flex sized inline in the markup is overridden here so the
     map and the chain cards stack into a single column. */
  .core-row {
    flex-direction: column;
    gap: 20px !important;
    margin-bottom: 24px !important;
  }

  .core-row > .col-map,
  .core-row > .col-chain {
    width: 100% !important;
  }

  .map-box {
    height: 300px;
  }

  .guide-row {
    flex-direction: column;
    gap: 12px !important;
    margin-bottom: 24px !important;
  }

  .feature-grid {
    grid-template-columns: 1fr;
    gap: 16px !important;
    margin-bottom: 32px !important;
  }

  .conclusion {
    padding: 14px 16px !important;
    margin-bottom: 24px !important;
  }

  /* ---- Detail module stacks on small screens ---- */
  .breadcrumb-bar {
    padding: 16px 0 12px;
  }

  .detail-layout {
    flex-direction: column;
  }

  .filter-panel {
    width: 100%;
    position: static;      /* sticky is pointless in a single column */
  }

  .chart-box {
    height: 320px;
  }

  .chart-toolbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .tab-btn {
    padding: 9px 10px;
    font-size: 13px;
  }

  .data-table th,
  .data-table td {
    padding: 8px 6px;
    font-size: 12px;
  }
}
