/*
 * sgy-vs-styles.css — 光变周期分析（VS）· 页面样式
 * 前缀 sgyv-，全部作用域在 .sgyv-app 内，不污染主题。
 * 配套：template-sgy-vs.php / sgy-vs-app.js / sgy-vs-core.js
 * 版权：孙国佑（Guoyou Sun）· 天体收藏家 · 小行星 546756
 */

.sgyv-app {
  --sgyv-primary: #165DFF;
  --sgyv-primary-dark: #0E42C5;
  --sgyv-gold: #E6A23C;
  --sgyv-green: #0E9F6E;
  --sgyv-red: #D92D20;
  --sgyv-text: #1F2937;
  --sgyv-sub: #667085;
  --sgyv-border: #E4E9F2;
  --sgyv-soft: #F7F9FC;
  --sgyv-radius: 14px;
  color: var(--sgyv-text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei",
    "PingFang SC", "Hiragino Sans GB", sans-serif;
  font-size: 14px;
  line-height: 1.6;
  width: min(1500px, 96vw);
  margin: 0 auto;
  padding: 0 0 64px;
}

@media (min-width: 901px) {
  .sgyv-app {
    margin-left: calc(50% - min(1500px, 96vw) / 2);
    margin-right: calc(50% - min(1500px, 96vw) / 2);
  }
}

.sgyv-app *,
.sgyv-app *::before,
.sgyv-app *::after { box-sizing: border-box; }

.sgyv-app h1,
.sgyv-app p,
.sgyv-app pre { margin: 0; }

.sgyv-app button,
.sgyv-app input,
.sgyv-app select { font-family: inherit; }

.sgyv-app button { cursor: pointer; }

/* ---------------- 页头 ---------------- */
.sgyv-hero {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 18px 22px;
  margin-bottom: 14px;
  background: linear-gradient(135deg, #F3F7FF 0%, #FFF 62%);
  border: 1px solid var(--sgyv-border);
  border-radius: 18px;
}
.sgyv-hero h1 {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: .5px;
  line-height: 1.25;
}

/* ---------------- 主布局 ---------------- */
.sgyv-layout {
  display: grid;
  grid-template-columns: var(--sgyv-side-w, 408px) 12px minmax(0, 1fr);
  gap: 0;
  align-items: start;
}
.sgyv-splitter {
  position: relative;
  align-self: stretch;
  min-height: 240px;
  cursor: col-resize;
  touch-action: none;
}
.sgyv-splitter span {
  position: absolute;
  left: 50%;
  top: 10px;
  bottom: 10px;
  width: 3px;
  margin-left: -1.5px;
  border-radius: 3px;
  background: #E3E8F1;
  transition: background .15s;
}
.sgyv-splitter:hover span,
body.sgyv-resizing .sgyv-splitter span { background: var(--sgyv-primary); }
body.sgyv-resizing { user-select: none; cursor: col-resize; }

.sgyv-side {
  position: sticky;
  top: 12px;
  max-height: calc(100vh - 24px);
  display: flex;
  flex-direction: column;
  background: var(--sgyv-soft);
  border: 1px solid var(--sgyv-border);
  border-radius: var(--sgyv-radius);
  overflow: hidden;
}
body.admin-bar .sgyv-side { top: 44px; max-height: calc(100vh - 56px); }

.sgyv-side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 10px;
  background: #fff;
  border-bottom: 1px solid var(--sgyv-border);
  font-weight: 700;
  font-size: 12.5px;
  flex: 0 0 auto;
}
.sgyv-side-fs {
  border: 1px solid var(--sgyv-border);
  background: var(--sgyv-soft);
  color: var(--sgyv-sub);
  border-radius: 7px;
  padding: 2px 8px;
  font-size: 11px;
  line-height: 1.5;
}
.sgyv-side-fs:hover { color: var(--sgyv-primary); border-color: #B9CCFF; background: #F5F8FF; }
.sgyv-side-body {
  padding: 8px;
  overflow: auto;
  overscroll-behavior: contain;
}
.sgyv-side.collapsed .sgyv-side-body { display: none; }

.sgyv-group {
  background: #fff;
  border: 1px solid var(--sgyv-border);
  border-radius: 11px;
  padding: 7px 8px 8px;
  margin-bottom: 7px;
}
.sgyv-group:last-child { margin-bottom: 0; }
.sgyv-group-head {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 700;
  margin-bottom: 6px;
}
.sgyv-group-head b {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #EAF0FF;
  color: var(--sgyv-primary);
  font-size: 11px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}
.sgyv-group-head small {
  font-size: 11px;
  color: var(--sgyv-sub);
  font-weight: 400;
  margin-left: auto;
}
.sgyv-group-toggle {
  margin-left: auto;
  padding: 1px 2px;
  border: 0;
  background: transparent;
  color: var(--sgyv-primary);
  font-size: 10.5px;
  font-weight: 500;
  line-height: 1.4;
  cursor: pointer;
}
.sgyv-group-toggle:hover { text-decoration: underline; }
.sgyv-group.sgyv-collapsed .sgyv-group-head { margin-bottom: 0; }
.sgyv-group.sgyv-collapsed .sgyv-group-body { display: none; }

.sgyv-grid2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 7px;
}
.sgyv-grid3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px 7px;
}
.sgyv-grid4 {
  display: grid;
  grid-template-columns: 1.2fr .85fr .8fr 1.15fr;
  gap: 6px 7px;
}
.sgyv-display-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 5px 2px;
}
.sgyv-display-row .sgyv-check {
  font-size: 10.5px;
  gap: 2px;
  flex: 0 0 auto;
  min-height: 28px;
}
.sgyv-display-row .sgyv-check input {
  width: 12px !important;
  height: 12px;
  min-width: 12px;
}
.sgyv-display-row .sgyv-mini {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: 0 0 auto;
  font-size: 10.5px;
  white-space: nowrap;
}
.sgyv-display-row .sgyv-mini input {
  width: 22px;
  margin-top: 0;
  padding: 5px 2px;
  text-align: center;
  font-size: 11.5px;
  -moz-appearance: textfield;
  appearance: textfield;
}
.sgyv-display-row .sgyv-mini input::-webkit-outer-spin-button,
.sgyv-display-row .sgyv-mini input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.sgyv-band-row {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
}
.sgyv-band-select {
  display: flex !important;
  align-items: center;
  gap: 4px;
  flex: 1 1 auto;
  min-width: 0;
  font-size: 10.5px;
  white-space: nowrap;
}
.sgyv-band-select select {
  flex: 1 1 50px;
  width: auto;
  min-width: 0;
  margin-top: 0;
  padding: 5px 20px 5px 6px;
  font-size: 11.5px;
}
.sgyv-btn-sm {
  flex: 0 0 auto;
  padding: 5px 7px;
  font-size: 11px;
}
.sgyv-app label {
  display: block;
  font-size: 11px;
  color: var(--sgyv-sub);
  min-width: 0;
}
.sgyv-app label input,
.sgyv-app label select,
.sgyv-title-input input {
  display: block;
  width: 100%;
  margin-top: 2px;
  padding: 5px 7px;
  border: 1px solid #D5DCE8;
  border-radius: 7px;
  background: #fff;
  color: var(--sgyv-text);
  font-size: 12.5px;
  line-height: 1.35;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.sgyv-app label input:focus,
.sgyv-app label select:focus,
.sgyv-title-input input:focus {
  border-color: var(--sgyv-primary);
  box-shadow: 0 0 0 3px rgba(22, 93, 255, .12);
}
.sgyv-app select { appearance: none; -webkit-appearance: none; padding-right: 24px;
  background-image: linear-gradient(45deg, transparent 50%, #98A2B3 50%),
    linear-gradient(135deg, #98A2B3 50%, transparent 50%);
  background-position: calc(100% - 13px) 52%, calc(100% - 8px) 52%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}
.sgyv-title-input { margin-top: 6px; }

.sgyv-row { display: flex; gap: 6px; margin-top: 6px; align-items: center; flex-wrap: wrap; }
.sgyv-row .sgyv-btn { flex: 1 1 auto; }
.sgyv-row-tight { margin-top: 5px; gap: 8px; }
.sgyv-check {
  display: flex !important;
  align-items: center;
  gap: 5px;
  color: var(--sgyv-text);
  font-size: 12px;
  white-space: nowrap;
  min-height: 30px;
}
.sgyv-check input {
  width: 13px !important;
  height: 13px;
  min-width: 13px;
  margin: 0 !important;
  padding: 0 !important;
  border: 0 !important;
  border-radius: 0;
  box-shadow: none !important;
  accent-color: var(--sgyv-primary);
  flex: 0 0 auto;
}
.sgyv-bins {
  flex: 1;
  min-width: 0;
  display: flex !important;
  flex-direction: row;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.sgyv-bins input { width: auto; flex: 1 1 70px; margin-top: 0; }

.sgyv-btn {
  border: 1px solid #D5DCE8;
  background: #fff;
  color: var(--sgyv-text);
  border-radius: 8px;
  padding: 7px 12px;
  font-size: 12.5px;
  font-weight: 600;
  transition: all .15s;
  white-space: nowrap;
}
.sgyv-btn:hover { border-color: #B7C3D6; background: #F8FAFF; }
.sgyv-btn.primary { background: var(--sgyv-primary); border-color: var(--sgyv-primary); color: #fff; }
.sgyv-btn.primary:hover { background: var(--sgyv-primary-dark); border-color: var(--sgyv-primary-dark); }
.sgyv-btn:disabled { opacity: .45; cursor: not-allowed; }

.sgyv-file {
  margin-top: 8px;
  font-size: 11.5px;
  color: var(--sgyv-primary);
  word-break: break-all;
}
.sgyv-note {
  font-size: 10.5px;
  color: #98A2B3;
  line-height: 1.45;
  margin-top: 4px;
}

.sgyv-progress {
  height: 4px;
  background: #EDF1F7;
  border-radius: 999px;
  overflow: hidden;
  margin: 9px 0 2px;
}
.sgyv-progress span {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #5B8CFF, #165DFF);
  transition: width .12s linear;
}

.sgyv-t0-wrap { margin-top: 0; display: none; grid-column: span 2; }
/* ---------------- 右侧工作区 ---------------- */
.sgyv-stage { min-width: 0; display: flex; flex-direction: column; }

.sgyv-tabs {
  display: flex;
  gap: 2px;
  overflow-x: auto;
  background: #fff;
  border: 1px solid var(--sgyv-border);
  border-radius: 12px 12px 0 0;
  padding: 4px 6px 0;
  scrollbar-width: none;
}
.sgyv-tabs::-webkit-scrollbar { display: none; }
.sgyv-tab {
  flex: 0 0 auto;
  border: 0;
  background: transparent;
  padding: 9px 14px 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--sgyv-sub);
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.sgyv-tab.active { color: var(--sgyv-primary); border-bottom-color: var(--sgyv-primary); }
.sgyv-tab span { font-size: 11px; opacity: .7; margin-left: 2px; }

.sgyv-msgbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 30px;
  padding: 4px 12px;
  background: #fff;
  border-left: 1px solid var(--sgyv-border);
  border-right: 1px solid var(--sgyv-border);
  border-bottom: 1px solid var(--sgyv-border);
  font-size: 12px;
  color: var(--sgyv-sub);
}
.sgyv-msg-ok { color: var(--sgyv-green); }
.sgyv-msg-warn { color: #B45309; }
.sgyv-msg-err { color: var(--sgyv-red); }
.sgyv-msg-busy { color: var(--sgyv-primary); }
.sgyv-msgbar-right { color: #98A2B3; font-size: 11px; white-space: nowrap; }

.sgyv-panel {
  display: none;
  background: #fff;
  border: 1px solid var(--sgyv-border);
  border-top: 0;
  border-radius: 0 0 14px 14px;
  padding: 10px 12px 12px;
}
.sgyv-panel.active { display: block; }

.sgyv-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}
.sgyv-panel-title { font-weight: 700; font-size: 13.5px; margin-right: 4px; }
.sgyv-toolbar-spacer { flex: 1 1 auto; }
.sgyv-tool {
  border: 1px solid var(--sgyv-border);
  background: #fff;
  color: var(--sgyv-sub);
  border-radius: 7px;
  padding: 4px 9px;
  font-size: 11.5px;
  line-height: 1.4;
}
.sgyv-tool:hover { color: var(--sgyv-primary); border-color: #B9CCFF; background: #F5F8FF; }

.sgyv-canvas-wrap {
  position: relative;
  height: clamp(502px, 73.7vh, 818px);
  border: 1px solid #EFF2F7;
  border-radius: 10px;
  overflow: hidden;
  background: #fff;
  touch-action: pan-y;
}
.sgyv-canvas-wrap canvas { width: 100%; height: 100%; display: block; outline: none; }
.sgyv-canvas-wrap canvas:focus-visible { outline: 2px solid rgba(22, 93, 255, .55); outline-offset: -2px; }
.sgyv-canvas-hint {
  margin-top: 6px;
  font-size: 11px;
  color: #98A2B3;
  line-height: 1.5;
}
.sgyv-rubber {
  display: none;
  position: absolute;
  border: 1px dashed var(--sgyv-primary);
  background: rgba(22, 93, 255, .08);
  pointer-events: none;
  z-index: 2;
}

/* ---------------- 表格 ---------------- */
.sgyv-table-wrap {
  overflow: auto;
  border: 1px solid var(--sgyv-border);
  border-radius: 10px;
  background: #fff;
  max-height: 64vh;
  overscroll-behavior: contain;
}
.sgyv-table-peaks { max-height: 58vh; }
.sgyv-table {
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
  font-size: 12px;
  min-width: 620px;
}
.sgyv-table th,
.sgyv-table td {
  padding: 5px 8px;
  border-bottom: 1px solid #F0F3F8;
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.sgyv-table thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: #F7F9FC;
  color: #475467;
  font-weight: 700;
  font-size: 11.5px;
}
.sgyv-table thead tr:first-child th { top: 0; }
/* 只有两行表头（数据表的“用途”行 + 列名行）时，第二行才需要下移；
   峰值表只有一行表头，不能用 last-child 偏移，否则会盖住第一行数据。 */
.sgyv-table thead .sgyv-role-row th { background: #EDF4FF; z-index: 4; top: 0; }
.sgyv-table thead tr:nth-child(2) th { top: 31px; }
.sgyv-table .sgyv-corner,
.sgyv-table .sgyv-rownum { text-align: left; color: #667085; font-weight: 600; }
.sgyv-table .sgyv-corner { font-size: 11px; }
.sgyv-table td.num { text-align: right; }
.sgyv-role-select {
  width: 100%;
  min-width: 62px;
  border: 1px solid #C9D8F5;
  border-radius: 6px;
  background: #fff;
  color: #1D4ED8;
  font-size: 11px;
  padding: 2px 16px 2px 4px;
}
.sgyv-table tbody tr.masked td { color: #B0B7C3; background: #F7F7F8; text-decoration: line-through; }
.sgyv-table tbody tr.flash td { background: #DBEAFE; transition: background .3s; }
.sgyv-table tbody tr:hover td { background: #FAFBFF; }
.sgyv-table tbody td[data-c] { cursor: cell; }
.sgyv-table tbody label { display: inline-flex; align-items: center; gap: 4px; color: #667085; }
.sgyv-table tbody input[type=checkbox] { accent-color: var(--sgyv-primary); }
.sgyv-empty { text-align: center !important; color: #98A2B3; padding: 26px 0 !important; }
.sgyv-table tbody tr[data-k] { cursor: pointer; }
.sgyv-table tbody tr[data-k]:hover td { background: #F2F7FF; }

/* ---------------- 报告 ---------------- */
.sgyv-report {
  white-space: pre-wrap;
  word-break: break-word;
  background: #0F172A;
  color: #D7E3F4;
  border-radius: 10px;
  padding: 16px 18px;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 12.5px;
  line-height: 1.75;
  min-height: 260px;
  overflow: auto;
}

/* ---------------- 浮层 / 菜单 / 提示 ---------------- */
.sgyv-loading[hidden],
.sgyv-menu[hidden],
.sgyv-toast[hidden] { display: none !important; }

.sgyv-loading {
  position: fixed;
  inset: 0;
  z-index: 9998;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, .28);
  backdrop-filter: blur(2px);
}
.sgyv-loading-box {
  background: #fff;
  border-radius: 14px;
  padding: 22px 28px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: 0 18px 60px rgba(15, 23, 42, .25);
  font-size: 13px;
  color: var(--sgyv-text);
  max-width: 86vw;
}
.sgyv-spinner {
  width: 20px;
  height: 20px;
  border: 2.5px solid #DCE6FF;
  border-top-color: var(--sgyv-primary);
  border-radius: 50%;
  animation: sgyv-spin .8s linear infinite;
  flex: 0 0 auto;
}
@keyframes sgyv-spin { to { transform: rotate(360deg); } }

.sgyv-menu {
  position: fixed;
  z-index: 9999;
  min-width: 210px;
  background: #fff;
  border: 1px solid var(--sgyv-border);
  border-radius: 10px;
  box-shadow: 0 14px 40px rgba(15, 23, 42, .18);
  padding: 5px;
  overflow: hidden;
}
.sgyv-menu-title {
  padding: 7px 10px 6px;
  font-size: 11.5px;
  color: #667085;
  border-bottom: 1px solid #F0F3F8;
  margin-bottom: 3px;
  font-variant-numeric: tabular-nums;
}
.sgyv-menu button {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  padding: 8px 10px;
  border-radius: 7px;
  font-size: 12.5px;
  color: var(--sgyv-text);
}
.sgyv-menu button:hover { background: #F2F6FF; color: var(--sgyv-primary); }

.sgyv-toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  z-index: 9999;
  background: #1F2D3D;
  color: #fff;
  border-radius: 999px;
  padding: 9px 18px;
  font-size: 12.5px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, .25);
}

/* ---------------- 响应式 ---------------- */
@media (max-width: 900px) {
  .sgyv-app { width: 100%; padding: 0 10px 48px; margin: 0; }
  .sgyv-hero { padding: 14px 16px; border-radius: 14px; }
  .sgyv-hero h1 { font-size: 21px; }
  .sgyv-layout { display: flex; flex-direction: column; gap: 12px; }
  .sgyv-splitter { display: none; }
  .sgyv-stage { order: 1; min-width: 0; width: 100%; max-width: 100%; }
  .sgyv-side {
    order: 2;
    position: static;
    max-height: none;
    margin-bottom: 0;
  }
  .sgyv-side .sgyv-side-body { max-height: none; overflow: visible; }
  .sgyv-canvas-wrap { height: 81.4vw; min-height: 440px; max-height: 594px; }
  .sgyv-tabs { border-radius: 10px 10px 0 0; }
  .sgyv-tab { padding: 8px 11px 7px; font-size: 12.5px; }
  .sgyv-msgbar { font-size: 11px; }
  .sgyv-msgbar-right { display: none; }
  .sgyv-table { font-size: 11px; min-width: 560px; }
  .sgyv-table-wrap { max-height: 56vh; }
}

@media (max-width: 560px) {
  .sgyv-hero h1 { font-size: 19px; }
  .sgyv-tab { padding: 8px 8px 7px; font-size: 12px; }
  .sgyv-group { padding: 9px; }
  .sgyv-display-row .sgyv-mini input { width: 30px; padding: 5px 2px; font-size: 16px; }
  .sgyv-app label input,
  .sgyv-app label select,
  .sgyv-title-input input { font-size: 16px; padding: 7px 8px; }
  .sgyv-role-select { font-size: 12px; }
  .sgyv-toolbar .sgyv-tool { padding: 4px 8px; }
  .sgyv-canvas-wrap { height: 99vw; min-height: 418px; max-height: 594px; }
  .sgyv-report { font-size: 11.5px; padding: 12px; }
}

/* 全屏：整个分析工作区，隐藏页头，把高度让给图表 */
.sgyv-app:fullscreen,
.sgyv-app.sgyv-fs-fallback {
  width: 100vw;
  max-width: none;
  height: 100vh;
  margin: 0;
  padding: 8px 10px 10px;
  overflow: auto;
  background: #F5F7FB;
}
.sgyv-app.sgyv-fs-fallback { position: fixed; inset: 0; z-index: 2147483000; }
.sgyv-app:fullscreen .sgyv-hero,
.sgyv-app.sgyv-fs-fallback .sgyv-hero { display: none; }
.sgyv-app:fullscreen .sgyv-side,
.sgyv-app.sgyv-fs-fallback .sgyv-side { max-height: calc(100vh - 18px); top: 8px; }
.sgyv-app:fullscreen .sgyv-canvas-wrap,
.sgyv-app.sgyv-fs-fallback .sgyv-canvas-wrap { height: calc(100vh - 142px); min-height: 360px; }

/* 打印时只留图与报告 */
@media print {
  .sgyv-side, .sgyv-tabs, .sgyv-msgbar, .sgyv-toolbar,
  .sgyv-loading, .sgyv-menu, .sgyv-toast { display: none !important; }
  .sgyv-app { width: 100%; }
  .sgyv-panel { display: block !important; page-break-inside: avoid; border: 0; }
  .sgyv-canvas-wrap { height: 520px; }
}
