:root {
  --blue: #0c429c;
  --blue-2: #1769c2;
  --line: #d8dee8;
  --panel: #ffffff;
  --bg: #f3f6f9;
  --text: #172033;
  --muted: #64748b;
  --danger: #d62929;
  --ok: #209b5a;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
}

.topbar {
  min-height: 104px;
  background: var(--blue);
  color: #fff;
  display: grid;
  grid-template-columns: 64px minmax(280px, .9fr) minmax(300px, 1.6fr) auto;
  align-items: center;
  gap: 20px;
  padding: 16px 28px;
  border-bottom: 1px solid #063276;
}

.logo-img {
  width: 64px;
  height: 64px;
  flex: 0 0 64px;
  object-fit: contain;
  border-radius: 50%;
}

.brand {
  min-width: 0;
  flex: 1;
}

.brand-title {
  font-size: 34px;
  line-height: 1.05;
  font-weight: 650;
  letter-spacing: 0;
}

.brand-subtitle {
  margin-top: 6px;
  font-size: 16px;
  line-height: 1.4;
}

.header-credit {
  min-width: 0;
  display: grid;
  gap: 4px;
  padding-left: 20px;
  border-left: 1px solid rgba(255, 255, 255, .2);
  line-height: 1.5;
}

.header-credit p { margin: 0; overflow-wrap: anywhere; }
.header-lab { font-size: 12px; font-weight: 600; color: #f3f7ff; }
.header-affiliation { font-size: 12px; color: #c8d8ee; }
.header-copyright { font-size: 11px; color: #b9cde8; }

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  grid-column: 4;
  grid-row: 1;
}

@media (max-width: 1200px) {
  .topbar { grid-template-columns: 64px minmax(0, 1fr) auto; row-gap: 14px; }
  .topbar-actions { grid-column: 3; }
  .header-credit { grid-column: 2 / -1; grid-row: 2; padding: 12px 0 0; border-left: 0; border-top: 1px solid rgba(255, 255, 255, .16); display: flex; flex-wrap: wrap; gap: 4px 20px; }
  .header-copyright { flex-basis: 100%; }
}

.admin-link,
.lang-toggle,
.guide-btn {
  color: #fff;
  text-decoration: none;
  border: 1px solid rgba(255, 255, 255, 0.48);
  padding: 8px 14px;
  border-radius: 6px;
  background: transparent;
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.lang-toggle {
  min-width: 74px;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(360px, 460px) 1fr;
  gap: 16px;
  padding: 16px;
  min-height: calc(100vh - 96px);
}

.control-pane,
.plot-pane {
  min-width: 0;
}

.panel,
.plot-card,
.metric-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.panel {
  padding: 14px;
  margin-bottom: 14px;
}

.panel-title,
.plot-title {
  font-weight: 700;
  margin-bottom: 12px;
}

.upload-area {
  display: grid;
  gap: 10px;
}

.file-input-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

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

.file-picker-row .secondary-btn {
  flex: 0 0 auto;
}

.file-name {
  min-width: 0;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

input,
select,
button {
  font: inherit;
}

input,
select {
  width: 100%;
  height: 34px;
  padding: 5px 8px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  background: #fff;
}

label {
  font-size: 13px;
  color: #334155;
  display: grid;
  gap: 5px;
}

.button-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

button {
  min-height: 36px;
  border: 0;
  border-radius: 6px;
  padding: 8px 14px;
  cursor: pointer;
  font-weight: 650;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.primary-btn {
  background: var(--blue-2);
  color: #fff;
}

.secondary-btn {
  background: #e7edf5;
  color: #172033;
}

.run-btn {
  background: #e72020;
  color: #fff;
  flex: 1 1 160px;
}

.danger-btn,
.icon-btn.danger {
  background: var(--danger);
  color: #fff;
}

.icon-btn {
  width: 32px;
  height: 32px;
  padding: 0;
  font-size: 22px;
  line-height: 1;
}

.scene-info {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 38px;
}

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

.coord-grid,
.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.coord-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.one-col {
  grid-template-columns: 1fr;
}

.check-line {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
}

.check-line input {
  width: 18px;
  height: 18px;
}

.dual-panel {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.dual-panel .panel {
  margin-bottom: 14px;
}

.progress-wrap {
  margin-top: 14px;
}

.progress-track {
  height: 12px;
  border-radius: 6px;
  background: #dbe4ef;
  overflow: hidden;
}

.progress-bar {
  width: 0%;
  height: 100%;
  background: var(--ok);
  transition: width 0.2s ease;
}

.steps {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}

.steps span.active {
  color: var(--ok);
  font-weight: 700;
}

.status-text {
  margin-top: 10px;
  color: var(--muted);
  min-height: 20px;
}

.rt-time {
  margin-top: 8px;
  color: #334155;
  font-size: 13px;
  line-height: 1.6;
  min-height: 20px;
}

.rt-time strong {
  color: #172033;
}

.plot-pane {
  display: grid;
  grid-template-rows: minmax(420px, 1.15fr) minmax(280px, 0.85fr);
  gap: 14px;
}

.plot-card {
  padding: 12px;
  min-width: 0;
}

.plot-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.plot-box {
  width: 100%;
  height: calc(100% - 28px);
  min-height: 350px;
}

.plot-box.small {
  min-height: 240px;
}

.hidden {
  display: none !important;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
}

.modal-body {
  width: min(480px, calc(100vw - 32px));
  background: #fff;
  border-radius: 8px;
  padding: 20px;
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.18);
}

.guide-modal-body {
  width: min(900px, calc(100vw - 32px));
  max-height: min(820px, calc(100vh - 32px));
  display: flex;
  flex-direction: column;
}

.guide-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.guide-header .modal-title {
  margin-bottom: 0;
}

.guide-content {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  margin-top: 14px;
  padding-right: 4px;
}

.guide-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  margin-top: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}

.guide-nav a,
.publication-item a {
  color: var(--blue);
  text-underline-offset: 3px;
  overflow-wrap: anywhere;
}

.guide-nav a:hover,
.publication-item a:hover {
  color: var(--blue-2);
}

.guide-content > .guide-section {
  scroll-margin-top: 8px;
}

.csv-table-wrap {
  border: 1px solid var(--line);
  border-radius: 6px;
}

.csv-table {
  min-width: 680px;
  table-layout: fixed;
  line-height: 1.5;
  font-size: 13px;
}

.csv-table th,
.csv-table td {
  vertical-align: top;
  overflow-wrap: anywhere;
}

.csv-table thead th:nth-child(1) { width: 23%; }
.csv-table thead th:nth-child(2) { width: 18%; }
.csv-table thead th:nth-child(3) { width: 15%; }

.csv-table tbody th {
  background: #f8fafc;
  font-weight: 500;
}

.csv-notes {
  margin-top: 14px;
  font-size: 13px;
}

.csv-notes li + li {
  margin-top: 7px;
}

.csv-example-label {
  margin-top: 14px;
}

.publication-list {
  margin: 0;
  padding-left: 26px;
}

.publication-item {
  padding-left: 6px;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.publication-item + .publication-item {
  border-top: 1px solid var(--line);
  margin-top: 18px;
  padding-top: 18px;
}

.publication-title {
  font-size: 15px;
  font-weight: 650;
}

.publication-authors,
.publication-meta {
  margin: 5px 0;
  font-size: 13px;
  color: var(--muted);
}

.publication-links {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 20px;
  font-size: 13px;
}

.publication-citation {
  margin-top: 8px;
  font-size: 13px;
}

.publication-citation summary {
  width: fit-content;
  cursor: pointer;
}

.publication-citation .guide-code {
  margin-top: 8px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.guide-left-column {
  min-width: 0;
}

.guide-workflow-section,
.guide-format-section {
  margin-top: 0;
}

.guide-format-section {
  margin-top: 24px;
}

.guide-video-section {
  margin-top: 24px;
}

.guide-video {
  display: block;
  width: 100%;
  max-height: 480px;
  aspect-ratio: 16 / 9;
  background: #111827;
  border-radius: 6px;
}

.guide-details-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(300px, 0.95fr);
  gap: 22px;
}

.guide-steps {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.guide-step {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  gap: 9px;
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafc;
}

.guide-step-number {
  display: inline-flex;
  width: 28px;
  height: 28px;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--blue-2);
  color: #fff;
  font-size: 13px;
  font-weight: 750;
}

.guide-step strong {
  display: block;
  color: var(--text);
  font-size: 13px;
}

.guide-step p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.guide-section + .guide-section {
  margin-top: 22px;
}

.guide-left-column .guide-section + .guide-section {
  margin-top: 22px;
}

.guide-material-section {
  display: flex;
  min-width: 0;
  min-height: 0;
  flex-direction: column;
}

.guide-section-title {
  font-weight: 750;
  margin-bottom: 8px;
}

.guide-note {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.guide-code {
  margin: 0;
  padding: 12px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafc;
  color: #172033;
  font-family: Consolas, "Courier New", monospace;
  font-size: 12px;
  line-height: 1.5;
}

.guide-download {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-top: 10px;
  text-decoration: none;
}

.guide-rules {
  margin: 0;
  padding-left: 20px;
  color: #334155;
  line-height: 1.65;
}

.guide-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.guide-table th,
.guide-table td {
  border: 1px solid var(--line);
  padding: 8px 10px;
  text-align: left;
}

.guide-table th {
  background: #edf3fa;
}

.guide-material-table-wrap {
  flex: 1 1 auto;
  min-height: 180px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.guide-material-table-wrap .guide-table th {
  position: sticky;
  top: 0;
}

.modal-title {
  font-weight: 800;
  margin-bottom: 10px;
}

.modal-text {
  white-space: pre-wrap;
  margin-bottom: 16px;
  color: #334155;
}

.site-footer {
  border-top: 1px solid var(--line);
  background: transparent;
  color: #627084;
  padding: 12px 24px;
  font-size: 12px;
  line-height: 1.65;
  text-align: center;
}

.site-footer-inner {
  max-width: 1600px;
  margin: 0 auto;
  display: grid;
  gap: 6px;
}

.site-footer-icp {
  display: inline-block;
  color: inherit;
  text-decoration: none;
  padding: 0;
}

.site-footer-icp:hover {
  color: var(--blue);
  text-decoration: underline;
}

.site-footer-icp:focus-visible {
  outline: 2px solid var(--blue-2);
  outline-offset: 3px;
}

@media (max-width: 900px) {
  .site-footer { padding: 12px 16px; }
}

.admin-shell {
  padding: 16px;
}

.admin-cards {
  display: grid;
  grid-template-columns: repeat(6, minmax(120px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.metric-card {
  padding: 14px;
}

.metric-card span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.metric-card strong {
  display: block;
  margin-top: 6px;
  font-size: 24px;
}

.admin-actions {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
}

.path-info {
  color: #334155;
  word-break: break-all;
  line-height: 1.7;
}

.table-wrap {
  overflow: auto;
}

.jobs-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.jobs-table th,
.jobs-table td {
  border-bottom: 1px solid var(--line);
  padding: 9px 8px;
  text-align: left;
  vertical-align: top;
}

@media (max-width: 1100px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .plot-pane {
    grid-template-rows: auto auto;
  }

  .admin-cards {
    grid-template-columns: repeat(3, minmax(120px, 1fr));
  }
}

@media (max-width: 720px) {
  .topbar {
    grid-template-columns: 52px minmax(0, 1fr);
    align-items: center;
    gap: 14px;
    padding: 14px 16px;
  }

  .topbar-actions {
    width: 100%;
    grid-column: 1 / -1;
    grid-row: 3;
  }

  .topbar .logo-img { width: 52px; height: 52px; }
  .header-credit { grid-column: 1 / -1; gap: 4px; display: grid; }

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

  .brand-subtitle {
    font-size: 14px;
  }

  .coord-grid,
  .settings-grid,
  .dual-panel,
  .plot-grid,
  .admin-cards,
  .guide-details-grid,
  .guide-steps {
    grid-template-columns: 1fr;
  }

  .guide-material-table-wrap {
    max-height: 360px;
  }

  .csv-table,
  .csv-table tbody {
    display: block;
    min-width: 0;
  }

  .csv-table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
  }

  .csv-table tbody tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 100px;
    border-bottom: 1px solid var(--line);
  }

  .csv-table tbody tr:last-child {
    border-bottom: 0;
  }

  .csv-table tbody th,
  .csv-table tbody td {
    border: 0;
    min-width: 0;
  }

  .csv-table tbody th,
  .csv-table tbody td:last-child {
    grid-column: 1 / -1;
  }

  .csv-table tbody th {
    font-weight: 650;
    border-bottom: 1px solid var(--line);
  }

  .csv-table tbody td::before {
    content: attr(data-label);
    display: block;
    margin-bottom: 3px;
    color: var(--muted);
    font-size: 11px;
  }
}
