:root {
  color-scheme: light;
  --bg: #f8fafc;
  --panel: #ffffff;
  --panel-soft: #ecfdf5;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --accent: #10b981;
  --accent-strong: #059669;
  --accent-soft: #d1fae5;
  --blue: #4f46e5;
  --warn: #d97706;
  --danger: #dc2626;
  --shadow: 0 4px 20px rgba(15, 23, 42, 0.06);
  --shadow-strong: 0 12px 30px rgba(15, 23, 42, 0.10);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  border-radius: 12px;
  min-height: 44px;
  padding: 0 16px;
  cursor: pointer;
  font-weight: 700;
  transition: transform 0.16s ease, box-shadow 0.16s ease, background 0.16s ease, border-color 0.16s ease;
}

button:active {
  transform: scale(0.98);
}

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

.primary {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  color: #fff;
  box-shadow: 0 8px 18px rgba(16, 185, 129, 0.24);
}

.primary:hover {
  background: linear-gradient(135deg, #34d399 0%, #059669 100%);
}

.secondary {
  background: #ffffff;
  color: var(--text);
  border: 1px solid var(--line);
}

.hidden {
  display: none !important;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(180deg, #ecfdf5 0%, #f8fafc 46%, #f1f5f9 100%);
}

.login-panel {
  width: min(420px, 100%);
  background: var(--panel);
  border: 0;
  border-radius: 18px;
  box-shadow: var(--shadow-strong);
  padding: 30px;
  display: grid;
  gap: 18px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
  line-height: 1.2;
  letter-spacing: 0;
}

h2 {
  font-size: 16px;
  line-height: 1.3;
  letter-spacing: 0;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
}

fieldset {
  margin: 0;
  padding: 0;
  border: 0;
}

legend {
  padding: 0;
  color: var(--muted);
}

input,
select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--text);
  padding: 0 12px;
}

input:focus,
select:focus {
  outline: 2px solid rgba(16, 185, 129, 0.18);
  border-color: var(--accent);
}

.app-shell {
  max-width: 1500px;
  margin: 0 auto;
  padding: 18px;
  display: grid;
  gap: 14px;
}

.topbar {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 18px;
  background: var(--panel);
  border: 0;
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.topbar p {
  margin-top: 6px;
  color: var(--muted);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.user-pill {
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  padding: 0 12px;
  font-weight: 700;
}

.message {
  min-height: 20px;
  color: var(--muted);
}

.message.ok {
  color: var(--accent-strong);
}

.message.error {
  color: var(--danger);
}

.hub-panel {
  background: #ffffff;
  border: 0;
  border-radius: 18px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.hub-head {
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
  background: #ffffff;
}

.hub-head span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
}

.module-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  padding: 14px;
}

.module-card {
  position: relative;
  min-height: 108px;
  display: grid;
  align-content: center;
  gap: 7px;
  padding: 18px 52px 18px 18px;
  border: 1px solid #edf2f7;
  border-radius: 16px;
  background: #ffffff;
  color: var(--text);
  text-align: left;
  overflow: hidden;
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.05);
}

.module-card:first-child {
  background: linear-gradient(135deg, #ecfdf5 0%, #ffffff 100%);
}

.module-card::before {
  content: "";
  position: absolute;
  right: 16px;
  top: 16px;
  width: 34px;
  height: 34px;
  border-radius: 12px;
  background: rgba(16, 185, 129, 0.12);
}

.module-card::after {
  content: ">";
  position: absolute;
  right: 28px;
  top: 21px;
  color: var(--accent-strong);
  font-size: 18px;
  font-weight: 800;
}

.module-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-strong);
  border-color: rgba(16, 185, 129, 0.28);
}

.module-card strong {
  font-size: 18px;
  line-height: 1.2;
}

.module-card span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.25;
}

.module-panel {
  display: none;
}

.module-panel.active {
  display: block;
}

.module-page-head {
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 2px;
  background: transparent;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

.module-page-head button {
  min-height: 36px;
  padding: 0 10px;
  border-radius: 10px;
  color: var(--muted);
}

.module-page-head h2 {
  font-size: 15px;
}

.module-page-head span {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
  padding: 0 14px 14px;
}

.metric {
  min-height: 88px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
  display: grid;
  align-content: space-between;
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.04);
}

.metric.featured {
  border-color: rgba(16, 185, 129, 0.3);
  background: linear-gradient(135deg, #ecfdf5 0%, #ffffff 100%);
}

.metric span {
  color: var(--muted);
}

.metric strong {
  font-size: 24px;
  letter-spacing: 0;
}

.split-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr);
  gap: 14px;
}

.panel {
  background: var(--panel);
  border: 0;
  border-radius: 18px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel-head {
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.panel-head span {
  color: var(--muted);
  display: block;
  margin-top: 4px;
}

.filter-toggle {
  min-width: 68px;
  min-height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  color: var(--accent-strong);
  background: var(--accent-soft);
  border-color: transparent;
  box-shadow: none;
  white-space: nowrap;
}

.panel.filter-collapsed .module-controls {
  display: none;
}

.module-controls {
  display: grid;
  gap: 10px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
  background: #f8fafc;
}

.compact-controls {
  grid-template-columns: minmax(150px, 180px) minmax(180px, 240px) 120px;
  align-items: end;
}

.range-controls {
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  align-items: end;
}

.cycle-controls {
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  align-items: end;
}

.weekday-picker {
  display: flex;
  align-items: end;
  gap: 6px;
  flex-wrap: wrap;
  min-width: min(100%, 430px);
}

.weekday-picker legend {
  flex: 0 0 100%;
  margin-bottom: 1px;
}

.weekday-picker label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 40px;
  padding: 0 8px;
  color: var(--text);
  border-radius: 12px;
  background: #ffffff;
  border: 1px solid var(--line);
}

.weekday-picker input {
  width: auto;
  min-height: auto;
  margin: 0;
}

.combo-chart {
  min-height: 278px;
  padding: 14px;
  display: grid;
  gap: 12px;
}

.combo-legend {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 9px 16px;
  color: var(--muted);
  font-weight: 800;
}

.combo-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.combo-legend .muted {
  color: #94a3b8;
}

.legend-bar {
  width: 18px;
  height: 8px;
  border-radius: 999px;
  display: inline-block;
}

.legend-line {
  width: 18px;
  height: 3px;
  border-radius: 999px;
  display: inline-block;
}

.legend-dash {
  width: 24px;
  height: 0;
  display: inline-block;
  border-top: 2px dashed #94a3b8;
}

.combo-scroll {
  overflow-x: auto;
  padding-bottom: 2px;
}

.combo-svg {
  width: 100%;
  height: auto;
  display: block;
}

.combo-plot-bg {
  fill: #ffffff;
  stroke: var(--line);
  stroke-width: 1;
}

.combo-grid-line {
  stroke: #edf2f7;
  stroke-width: 1;
}

.combo-axis-line {
  stroke: #cbd5e1;
  stroke-width: 1;
}

.combo-axis-text {
  fill: #94a3b8;
  font-size: 12px;
  font-weight: 800;
}

.combo-x-date {
  fill: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.combo-x-weekday {
  fill: #94a3b8;
  font-size: 11px;
  font-weight: 700;
}

.combo-average-line {
  stroke: var(--accent-strong);
  stroke-width: 1.5;
  stroke-dasharray: 6 5;
  opacity: 0.75;
}

.combo-average-text {
  fill: #0f766e;
  font-size: 12px;
  font-weight: 800;
}

.combo-bar {
  opacity: 0.9;
}

.combo-bar:hover {
  opacity: 1;
}

.combo-line-muted {
  opacity: 0.72;
}

.combo-hover-zone {
  cursor: crosshair;
  pointer-events: all;
}

.trend-tooltip {
  position: fixed;
  z-index: 50;
  display: grid;
  gap: 6px;
  max-width: 260px;
  padding: 12px 14px;
  border-radius: 10px;
  background: rgba(15, 23, 42, 0.92);
  color: #ffffff;
  box-shadow: 0 14px 28px rgba(15, 23, 42, 0.22);
  pointer-events: none;
  opacity: 0;
  transform: translateY(2px);
}

.trend-tooltip.visible {
  opacity: 1;
  transform: translateY(0);
}

.trend-tooltip strong {
  font-size: 14px;
}

.trend-tooltip span {
  color: #e2e8f0;
  white-space: nowrap;
}

.compare-grid {
  padding: 14px;
  display: grid;
  gap: 8px;
}

.compare-row {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr) minmax(0, 1fr) 88px;
  gap: 8px;
  align-items: center;
  min-height: 38px;
  border-bottom: 1px solid var(--line);
}

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

.compare-row strong {
  font-size: 16px;
}

.delta-up {
  color: var(--accent-strong);
}

.delta-down {
  color: var(--danger);
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 920px;
}

#cycleTable {
  min-width: 620px;
  table-layout: fixed;
}

#cycleTable th,
#cycleTable td {
  height: auto;
  min-height: 36px;
  padding: 8px 8px;
  white-space: normal;
}

#anchorTable {
  min-width: 760px;
}

.detail-wrap table {
  min-width: 2460px;
}

th,
td {
  height: 40px;
  padding: 0 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f8fafc;
  color: var(--muted);
  font-weight: 700;
}

td.num,
th.num {
  text-align: right;
}

.sort-head {
  width: 100%;
  min-height: 34px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  gap: 6px;
  border-radius: 0;
  background: transparent;
  color: inherit;
  box-shadow: none;
  text-align: inherit;
}

th.num .sort-head {
  justify-content: flex-end;
}

.sort-head:hover,
.sort-head.active {
  color: var(--text);
  background: transparent;
  box-shadow: none;
}

.sort-head:active {
  transform: none;
}

.sort-mark {
  display: inline-grid;
  gap: 2px;
  width: 10px;
}

.sort-mark i {
  display: block;
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  opacity: 0.28;
}

.sort-up {
  border-bottom: 6px solid #94a3b8;
}

.sort-down {
  border-top: 6px solid #94a3b8;
}

.sort-mark .on.sort-up {
  border-bottom-color: var(--accent-strong);
  opacity: 1;
}

.sort-mark .on.sort-down {
  border-top-color: #ff7a5c;
  opacity: 1;
}

tr:hover td {
  background: #f8fafc;
}

.note-toggle {
  width: 34px;
  min-width: 34px;
  min-height: 30px;
  padding: 0;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--muted);
  box-shadow: none;
}

.note-toggle.has-note {
  border-color: rgba(16, 185, 129, 0.36);
  background: #ecfdf5;
  color: var(--accent-strong);
}

.note-row td {
  height: auto;
  padding: 0;
  white-space: normal;
  background: #f8fafc;
}

.note-row:hover td {
  background: #f8fafc;
}

.note-editor {
  display: grid;
  gap: 10px;
  margin: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #ffffff;
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.04);
}

.note-editor-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.note-editor-head strong {
  font-size: 15px;
}

.note-editor-head span,
.note-actions span {
  color: var(--muted);
}

.note-editor textarea {
  width: 100%;
  min-height: 112px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  color: var(--text);
  font: inherit;
  line-height: 1.5;
}

.note-editor textarea:focus {
  outline: 2px solid rgba(16, 185, 129, 0.18);
  border-color: var(--accent);
}

.note-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.note-action-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: #e9f3ff;
  color: var(--blue);
}

.status-pill.warn {
  background: #fff3e4;
  color: var(--warn);
}

.compare-good {
  color: var(--accent-strong);
  font-weight: 800;
}

.compare-mid {
  color: var(--warn);
  font-weight: 800;
}

.compare-bad {
  color: var(--danger);
  font-weight: 800;
}

.empty {
  padding: 12px 0;
  color: var(--muted);
}

.module-note {
  min-height: 0;
  padding: 0 14px 12px;
  color: var(--text);
  display: grid;
  gap: 8px;
}

.module-note:empty {
  display: none;
}

.module-note div {
  display: grid;
  grid-template-columns: 1fr;
  gap: 4px;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f8fafc;
}

.module-note strong {
  color: var(--text);
}

.module-note span {
  color: var(--text);
  font-weight: 800;
}

.metric-hot {
  color: var(--danger);
  font-weight: 800;
}

h3 {
  margin: 0;
  font-size: 15px;
  line-height: 1.3;
  letter-spacing: 0;
}

.admin-layout {
  display: grid;
  grid-template-columns: minmax(260px, 360px) minmax(0, 1fr);
  gap: 14px;
  padding: 14px;
  background: #f8fafc;
}

.admin-form,
.admin-list-panel,
.admin-target-panel {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.04);
}

.admin-form {
  display: grid;
  gap: 12px;
  align-content: start;
}

.admin-list-panel,
.admin-target-panel {
  display: grid;
  gap: 10px;
  min-width: 0;
}

.admin-target-panel {
  grid-column: 1 / -1;
}

.admin-list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.admin-list-head span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
}

.users-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 10px;
}

.user-card {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #ffffff;
}

.user-card.is-disabled {
  background: #f8fafc;
  opacity: 0.72;
}

.user-main {
  display: grid;
  gap: 4px;
}

.user-main strong {
  font-size: 16px;
}

.user-main span,
.user-meta {
  color: var(--muted);
}

.user-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.role-pill,
.status-dot {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 9px;
  border-radius: 999px;
  font-weight: 800;
  font-size: 12px;
}

.role-pill {
  background: #eef2ff;
  color: var(--blue);
}

.role-pill.super_admin {
  background: #ecfdf5;
  color: var(--accent-strong);
}

.role-pill.anchor {
  background: #fff7ed;
  color: var(--warn);
}

.status-dot.ok {
  background: #dcfce7;
  color: #15803d;
}

.status-dot.off {
  background: #fee2e2;
  color: var(--danger);
}

.user-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.danger-action {
  color: var(--danger);
  border-color: #fecaca;
}

.target-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 10px;
}

.target-row {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #f8fafc;
}

.target-row span {
  color: var(--text);
  font-weight: 800;
}

.roi-card {
  border-left: 5px solid var(--warn) !important;
}

.roi-card.ok {
  border-left-color: var(--accent-strong) !important;
  background: #ecfdf5 !important;
}

.roi-card.bad {
  border-left-color: var(--danger) !important;
  background: #fff7ed !important;
}

.roi-card.warn {
  border-left-color: var(--warn) !important;
  background: #fffbeb !important;
}

@media (max-width: 1100px) {
  .metric-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .split-grid,
  .admin-layout,
  .compact-controls,
  .range-controls,
  .cycle-controls {
    grid-template-columns: 1fr 1fr;
  }

  .cycle-controls .weekday-picker {
    grid-column: 1 / -1;
  }
}

@media (max-width: 720px) {
  .app-shell {
    padding: 10px;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
    gap: 12px;
  }

  .top-actions {
    justify-content: stretch;
  }

  .top-actions > * {
    flex: 1 1 auto;
  }

  .filter-band,
  .split-grid,
  .admin-layout,
  .compact-controls,
  .range-controls,
  .cycle-controls {
    grid-template-columns: 1fr;
  }

  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    padding: 12px;
  }

  .metric {
    min-height: 96px;
    border-radius: 14px;
    padding: 13px;
  }

  .metric.featured {
    grid-column: span 1;
  }

  .metric strong {
    font-size: 22px;
  }

  .hub-head {
    align-items: flex-start;
    flex-direction: column;
  }

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

  .module-card {
    min-height: 86px;
    border-radius: 14px;
  }

  .module-page-head {
    align-items: center;
    flex-direction: row;
    padding: 0 2px;
  }

  .compare-row {
    grid-template-columns: 78px 1fr 1fr 76px;
  }

  .combo-chart {
    padding: 12px;
  }

  .combo-legend {
    font-size: 12px;
    gap: 8px 12px;
  }

  .admin-list-head,
  .user-actions {
    grid-template-columns: 1fr;
  }

  .admin-list-head {
    align-items: stretch;
    flex-direction: column;
  }

}
