:root {
  --bg: #fbfaf7;
  --bg-2: #f7f3eb;
  --panel: #ffffff;
  --panel-2: #ffffff;
  --line: #e7d8c3;
  --line-2: #efe4d5;
  --ink: #202020;
  --muted: #8a8176;
  --dim: #a89d90;
  --cyan: #11a3a7;
  --teal: #2f8ef7;
  --lime: #4ebd73;
  --amber: #f39a2f;
  --coral: #e76763;
  --violet: #7d70f0;
  --rose: #e55fa0;
  --radius: 8px;
  --shadow: 0 8px 20px rgba(74, 55, 33, 0.05);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: "PingFang SC", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.28;
}

button, input, select { font: inherit; }
button { color: inherit; }

h1, h2, h3, p { margin: 0; line-height: 1.15; }

h1, h2, h3 {
  letter-spacing: 0;
}

h1, h2 {
  font-family: "Noto Serif SC", "Songti SC", "STSong", serif;
}

h1 { font-size: 22px; font-weight: 900; }
h2 { font-size: 36px; font-weight: 900; }
h3 { font-size: 17px; font-weight: 900; }

.appbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 72px;
  padding: 10px 16px;
  background: rgba(255, 255, 255, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(18px);
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 9px;
  background: #202020;
  border: 1px solid #202020;
  color: #ffffff;
  font-weight: 800;
  font-size: 18px;
}

.brand p,
.eyebrow,
.stamp,
.panel-meta,
.control-label,
.metric-sub,
.muted {
  color: var(--muted);
}

.brand p { margin-top: 2px; font-size: 13px; font-weight: 700; }

.tabs {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex: 1 1 auto;
  overflow-x: auto;
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar,
.pill-row::-webkit-scrollbar { display: none; }

.tab {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 18px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #ffffff;
  color: #3f3a34;
  font-weight: 800;
  cursor: pointer;
  white-space: nowrap;
}

.tab.active {
  background: #202020;
  border-color: #202020;
  color: #ffffff;
}

.tab:hover {
  border-color: #c9b99f;
  background: #fffaf2;
}

.mobile-sticky-tabs {
  display: none;
}

.tab svg,
.icon-btn svg {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
}

.actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  font-weight: 800;
  cursor: pointer;
}

.icon-btn.primary {
  border-color: rgba(17, 163, 167, 0.22);
  background: #e9f8f5;
  color: #0d7771;
}

.shell {
  width: min(1600px, 100%);
  margin: 0 auto;
  padding: 10px 18px 30px;
}

.page { display: none; }
.page.active { display: block; }

.page-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 6px;
}

.eyebrow {
  margin-bottom: 2px;
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
}

.stamp {
  font-size: 12px;
}

.panel,
.metric-card,
.center-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  box-shadow: var(--shadow);
}

.panel {
  padding: 10px 12px;
  margin-bottom: 8px;
}

.panel-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
}

.panel-title-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.click-hint-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 24px;
  padding: 0 10px;
  border: 1px solid rgba(47, 142, 247, 0.28);
  border-radius: 999px;
  background: #e8f3ff;
  color: #1f75c9;
  font-size: 12px;
  font-weight: 900;
  line-height: 1;
  white-space: nowrap;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.62);
}

.click-hint-btn[hidden] {
  display: none;
}

.panel-meta {
  font-size: 12px;
}

.controls-panel {
  padding: 10px 12px;
}

.region-module-control {
  margin-top: 12px;
}

.store-controls {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.control-label {
  margin-bottom: 6px;
  font-size: 12px;
}

select,
input[type="search"] {
  width: 100%;
  min-height: 36px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  outline: none;
}

select:focus,
input[type="search"]:focus {
  border-color: #202020;
  box-shadow: 0 0 0 3px rgba(32, 32, 32, 0.06);
}

.metric-grid {
  display: grid;
  gap: 8px;
  margin-bottom: 8px;
}

.metric-grid.six { grid-template-columns: repeat(6, minmax(0, 1fr)); }

.metric-card {
  position: relative;
  min-height: 88px;
  padding: 10px 12px 8px;
  overflow: hidden;
}

.metric-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 2px;
  background: var(--accent, var(--cyan));
}

.metric-label {
  color: #354255;
  font-size: 12px;
  font-weight: 900;
}

.metric-value {
  margin-top: 4px;
  font-family: "Avenir Next Condensed", "PingFang SC", sans-serif;
  font-size: 34px;
  font-weight: 900;
  line-height: 1;
  color: #151515;
  letter-spacing: 0;
}

.metric-value.text {
  font-size: 24px;
  line-height: 1.02;
  word-break: break-all;
}

.metric-sub {
  margin-top: 4px;
  font-size: 11px;
  font-weight: 700;
}

.center-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}

.center-card {
  position: relative;
  min-height: 142px;
  padding: 12px 14px;
  overflow: hidden;
}

.center-card::after {
  content: "";
  position: absolute;
  inset: auto 0 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, rgba(17, 24, 39, 0.08), transparent);
}

.center-name {
  margin-bottom: 8px;
  font-size: 17px;
  font-weight: 900;
}

.center-row {
  display: grid;
  grid-template-columns: 68px minmax(0, 1fr);
  align-items: baseline;
  gap: 10px;
  min-height: 24px;
  color: #354255;
  font-size: 12px;
  font-weight: 900;
}

.center-row b {
  justify-self: end;
  font-family: "Arial Black", Arial, "Helvetica Neue", sans-serif;
  font-size: 12px;
  line-height: 1;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.center-row .leader {
  color: var(--accent, #31a7ff);
  font-size: 12px;
}

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

.module-scope-controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 2px 0 10px;
}

.chart {
  width: 100%;
  height: 320px;
}

.chart.tall { height: 380px; }
.chart.compact { height: 280px; }
.chart.heatmap { height: 520px; }
.chart.heatmap.large { height: 620px; }

#moduleStructureChart {
  overflow: auto;
}

.pill-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #ffffff;
  color: #4b443d;
  font-weight: 800;
  cursor: pointer;
  white-space: nowrap;
}

.pill.active {
  background: #202020;
  border-color: #202020;
  color: #ffffff;
}

.region-pill .pill {
  min-width: 102px;
  justify-content: center;
  padding: 0 14px;
}

.region-pill {
  flex-wrap: wrap;
  overflow: visible;
}

.table-wrap {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: auto;
  max-height: 280px;
  background: #ffffff;
}

.table-wrap.expanded {
  max-height: 700px;
}

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

.data-table th,
.data-table td {
  padding: 7px 9px;
  border-bottom: 1px solid rgba(232, 218, 197, 0.55);
  text-align: left;
  white-space: nowrap;
}

.data-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #fbf7ef;
  color: #24211d;
  font-weight: 900;
}

.data-table tr:nth-child(even) td {
  background: rgba(245, 248, 252, 0.8);
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}

.badge.warn {
  background: rgba(255, 124, 114, 0.12);
  color: #ff9d94;
  border: 1px solid rgba(255, 124, 114, 0.28);
}

.badge.ok {
  background: rgba(77, 225, 193, 0.12);
  color: #12906f;
  border: 1px solid rgba(77, 225, 193, 0.26);
}

.segmented {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.segmented.compact .pill {
  min-height: 30px;
  padding: 0 12px;
  font-size: 12px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%) translateY(20px);
  min-width: 240px;
  max-width: min(92vw, 560px);
  padding: 12px 14px;
  border: 1px solid rgba(219, 228, 238, 1);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.98);
  color: #132033;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}

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

.app-footer {
  width: fit-content;
  max-width: calc(100vw - 32px);
  margin: 12px auto 18px;
  padding: 7px 17px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #ffffff;
  color: #25211c;
  box-shadow: 0 8px 20px rgba(74, 55, 33, 0.05);
  font-family: "Arial Black", "PingFang SC", sans-serif;
  font-size: 12px;
  font-weight: 900;
  line-height: 1;
  letter-spacing: 0;
  text-align: center;
}

.app-footer a {
  color: inherit;
  text-decoration: none;
}

@media (max-width: 1080px) {
  .metric-grid.six { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .center-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .split-grid { grid-template-columns: 1fr; }
  .store-controls { grid-template-columns: 1fr; }
}

@media (max-width: 860px) {
  .appbar {
    position: static;
    flex-wrap: wrap;
    align-items: flex-start;
  }
  .brand { min-width: 0; }
  .appbar .tabs { display: none; }
  .mobile-sticky-tabs {
    position: sticky;
    top: 0;
    z-index: 80;
    display: flex;
    width: 100%;
    justify-content: flex-start;
    gap: 8px;
    padding: 10px 18px;
    overflow-x: auto;
    background: rgba(255, 255, 255, 0.96);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(18px);
  }
  .mobile-sticky-tabs .tab {
    flex: 0 0 auto;
  }
  .metric-grid.six { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric-value { font-size: 28px; }
  .center-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .app-footer {
    padding: 6px 14px;
    font-size: 12px;
  }
}

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

.structure-pies {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
  min-width: 1280px;
}

.structure-pie-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdfa;
  padding: 8px;
  min-height: 268px;
}

.structure-pie-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  color: #24211d;
}

.structure-pie-title span {
  font-size: 15px;
  font-weight: 900;
}

.structure-pie-title b {
  font-family: "Noto Serif SC", "Songti SC", serif;
  font-size: 18px;
  font-weight: 900;
}

.structure-pie-chart {
  height: 230px;
  width: 100%;
}

.store-insight-board {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdfa;
  overflow: auto;
  max-height: 360px;
}

.store-insight-list {
  display: grid;
  gap: 0;
}

.store-insight-row {
  display: grid;
  grid-template-columns: 80px minmax(180px, 1fr) 190px 70px;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  padding: 7px 10px;
  border-bottom: 1px solid rgba(232, 218, 197, 0.68);
}

.store-insight-row:last-child {
  border-bottom: 0;
}

.store-insight-type {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.store-insight-name {
  color: #24211d;
  font-weight: 900;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.store-insight-value {
  display: grid;
  gap: 2px;
  justify-items: end;
}

.store-insight-value b {
  color: #24211d;
  font-size: 16px;
  font-weight: 900;
}

.store-insight-value span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.store-insight-ratio {
  justify-self: end;
  min-width: 52px;
  text-align: right;
  font-size: 17px;
  font-weight: 900;
}

.store-insight-row.high .store-insight-ratio { color: #16a66a; }
.store-insight-row.watch .store-insight-ratio { color: #f39a2f; }
.store-insight-row.low .store-insight-ratio { color: #e1574f; }
.store-insight-row.flat .store-insight-ratio { color: #5d554d; }

.module-compare {
  min-width: 1040px;
  padding: 6px 2px;
}

@media (max-width: 860px) {
  .mobile-sticky-tabs {
    padding: 5px 18px 4px;
  }

  .mobile-sticky-tabs .tab {
    min-height: 36px;
    padding: 0 14px;
  }

  #module > .controls-panel,
  #region > .controls-panel {
    position: sticky;
    top: 64px;
    z-index: 70;
    background: rgba(255, 255, 255, 0.98);
    box-shadow: 0 8px 18px rgba(74, 55, 33, 0.08);
    backdrop-filter: blur(16px);
  }

  #module > .controls-panel {
    top: 50px;
    padding: 6px 10px;
    margin-bottom: 6px;
    border-radius: 0 0 8px 8px;
  }

  #region > .controls-panel {
    top: 44px;
    padding: 4px 10px 6px;
    margin-bottom: 6px;
    border-radius: 0 0 8px 8px;
  }

  #region > .controls-panel .control-label {
    display: none;
  }

  #region > .controls-panel .region-module-control {
    margin-top: 6px;
  }

  #region > .controls-panel .pill-row {
    padding-bottom: 0;
  }

  #module > .controls-panel .control-label {
    display: none;
  }

  #module > .controls-panel .pill-row {
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    width: 100%;
    padding-bottom: 0;
    -webkit-overflow-scrolling: touch;
  }

  #module > .controls-panel .pill {
    flex: 0 0 auto;
    min-width: 112px;
    min-height: 34px;
  }

  #moduleSpecialPanel .panel-head {
    display: grid;
    grid-template-columns: 1fr;
    gap: 6px;
    align-items: start;
  }

  #moduleSpecialPanel .panel-title-row {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 8px;
    width: 100%;
  }

  #moduleSpecialTitle {
    flex: 0 0 auto;
    white-space: nowrap;
    font-size: 18px;
    line-height: 1.1;
  }

  #moduleSpecialClickHint {
    flex: 0 0 auto;
  }

  #moduleSpecialMeta {
    width: 100%;
    max-width: 100%;
    font-size: 12px;
    line-height: 1.35;
  }

  #regionTabs,
  #regionModuleTabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    width: 100%;
    padding-bottom: 6px;
    -webkit-overflow-scrolling: touch;
  }

  #regionTabs .pill,
  #regionModuleTabs .pill {
    flex: 0 0 auto;
    min-width: 112px;
  }

  #module .triple-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  #module .triple-grid .panel {
    width: 100%;
    min-width: 0;
  }

  #module .triple-grid .chart {
    width: 100%;
    min-height: 300px;
  }
}
