/* Group Performance & Daily Collection/Enrollment Report Styles */
/* Optimized for Clean, Modern & High-Aesthetic SaaS Design (白天 / 夜间双主题完美适配) */

/* ==========================================================================
   0. THEME TOKENS (主题控制与颜色变量变量定义)
   ========================================================================== */
:root,
html,
html[data-theme="light"] {
  --gp-card-bg: #ffffff;
  --gp-toolbar-bg: #ffffff;
  --gp-input-bg: #ffffff;
  --gp-btn-bg: #ffffff;
  --gp-btn-hover: rgba(100, 116, 139, 0.08);
  --gp-text: #0f172a;
  --gp-text-muted: #64748b;
  --gp-border: #e2e8f0;
  --gp-border-strong: #cbd5e1;
  --gp-th-row1-bg: #f1f5f9;
  --gp-th-row2-bg: #f8fafc;
  --gp-tbody-bg: #ffffff;
  --gp-level0-bg: #f8fafc;
  --gp-level1-bg: #ffffff;
  --gp-row-hover: #eff6ff;
  --gp-total-bg: #f1f5f9;
  --gp-refund-bg: #fff1f2;
  --gp-zero-color: #94a3b8;
}

/* System Dark Mode ONLY when user hasn't explicitly switched to Light Mode */
@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) {
    --gp-card-bg: #1e293b;
    --gp-toolbar-bg: #1e293b;
    --gp-input-bg: #0f172a;
    --gp-btn-bg: #0f172a;
    --gp-btn-hover: rgba(255, 255, 255, 0.06);
    --gp-text: #f8fafc;
    --gp-text-muted: #94a3b8;
    --gp-border: #334155;
    --gp-border-strong: #475569;
    --gp-th-row1-bg: #1e293b;
    --gp-th-row2-bg: #0f172a;
    --gp-tbody-bg: #0f172a;
    --gp-level0-bg: #1e293b;
    --gp-level1-bg: #0f172a;
    --gp-row-hover: #1e293b;
    --gp-total-bg: #1e293b;
    --gp-refund-bg: rgba(244, 63, 94, 0.12);
    --gp-zero-color: #475569;
  }
}

/* Manual Dark Mode Override */
html[data-theme="dark"] {
  --gp-card-bg: #1e293b;
  --gp-toolbar-bg: #1e293b;
  --gp-input-bg: #0f172a;
  --gp-btn-bg: #0f172a;
  --gp-btn-hover: rgba(255, 255, 255, 0.06);
  --gp-text: #f8fafc;
  --gp-text-muted: #94a3b8;
  --gp-border: #334155;
  --gp-border-strong: #475569;
  --gp-th-row1-bg: #1e293b;
  --gp-th-row2-bg: #0f172a;
  --gp-tbody-bg: #0f172a;
  --gp-level0-bg: #1e293b;
  --gp-level1-bg: #0f172a;
  --gp-row-hover: #1e293b;
  --gp-total-bg: #1e293b;
  --gp-refund-bg: rgba(244, 63, 94, 0.12);
  --gp-zero-color: #475569;
}

.gp-container {
  display: flex;
  flex-direction: column;
  gap: 18px;
  font-family: var(--font-sans, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif);
  color: var(--gp-text);
}

/* ==========================================================================
   1. KPI Summary Banner (指标概览卡片)
   ========================================================================== */
.gp-kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 14px;
}

.gp-kpi-card {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 10px;
  padding: 16px 18px;
  border: 1px solid var(--gp-border);
  border-radius: 10px;
  background: var(--gp-card-bg);
  box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.04);
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.gp-kpi-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px -4px rgba(0, 0, 0, 0.08);
  border-color: var(--gp-border-strong);
}

.gp-kpi-primary {
  background:
    radial-gradient(circle at 100% 0%, rgba(16, 185, 129, 0.12), transparent 55%),
    var(--gp-card-bg);
  border-color: rgba(16, 185, 129, 0.35);
}

.gp-kpi-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.gp-kpi-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--gp-text-muted);
  letter-spacing: 0.01em;
}

.gp-kpi-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(100, 116, 139, 0.12);
  color: var(--gp-text-muted);
}

.gp-kpi-badge.primary {
  background: rgba(16, 185, 129, 0.14);
  color: #059669;
}

.gp-kpi-badge.danger {
  background: rgba(244, 63, 94, 0.12);
  color: #e11d48;
}

.gp-kpi-value {
  font-size: 26px;
  font-weight: 700;
  color: var(--gp-text);
  line-height: 1.15;
  font-family: var(--font-mono, "JetBrains Mono", "Roboto Mono", monospace);
  font-variant-numeric: tabular-nums;
}

.gp-kpi-value.positive {
  color: #059669;
}

.gp-kpi-value.negative {
  color: #e11d48;
}

.gp-kpi-unit {
  font-size: 14px;
  font-weight: 500;
  color: var(--gp-text-muted);
  margin-left: 2px;
}

.gp-kpi-footer {
  font-size: 12px;
  color: var(--gp-text-muted);
  line-height: 1.4;
}

/* ==========================================================================
   2. Filter & Action Toolbar (操作栏)
   ========================================================================== */
.gp-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: var(--gp-toolbar-bg);
  border: 1px solid var(--gp-border);
  border-radius: 10px;
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.02);
}

.gp-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

.gp-month-select-wrap,
.gp-search-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.gp-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--gp-text);
}

.gp-select,
.gp-search-input {
  height: 34px;
  padding: 0 12px;
  border: 1px solid var(--gp-border-strong);
  border-radius: 6px;
  background: var(--gp-input-bg);
  color: var(--gp-text);
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.gp-select:focus,
.gp-search-input:focus {
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.12);
}

.gp-search-input {
  width: 200px;
}

.gp-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.gp-btn-group {
  display: inline-flex;
  border: 1px solid var(--gp-border-strong);
  border-radius: 6px;
  overflow: hidden;
}

.gp-btn-group .gp-btn {
  border: none;
  border-radius: 0;
  border-right: 1px solid var(--gp-border-strong);
}

.gp-btn-group .gp-btn:last-child {
  border-right: none;
}

.gp-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  padding: 0 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.15s ease;
  border: 1px solid var(--gp-border-strong);
  background: var(--gp-btn-bg);
  color: var(--gp-text);
}

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

.gp-btn svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
}

.gp-btn-primary {
  background: #10b981;
  color: #ffffff;
  border-color: #059669;
}

.gp-btn-primary:hover {
  background: #059669;
  color: #ffffff;
}

.gp-btn-compact.active {
  background: #eff6ff;
  border-color: #3b82f6;
  color: #2563eb;
}

/* ==========================================================================
   3. Spreadsheet Table Styling (层级交叉报表)
   ========================================================================== */
.gp-table-wrapper {
  overflow: auto;
  max-height: calc(100vh - 275px);
  border: 1px solid var(--gp-border);
  border-radius: 10px;
  background: var(--gp-tbody-bg);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.04);
}

.gp-table {
  width: max-content;
  min-width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
  text-align: center;
}

/* Table Headers */
.gp-table thead tr:first-child th {
  background-color: var(--gp-th-row1-bg);
  color: var(--gp-text);
  font-weight: 700;
  padding: 11px 14px;
  border-bottom: 1px solid var(--gp-border-strong);
  border-right: 1px solid var(--gp-border);
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 15;
}

.gp-table thead tr:nth-child(2) th {
  background-color: var(--gp-th-row2-bg);
  color: var(--gp-text);
  font-weight: 600;
  padding: 9px 12px;
  border-bottom: 1px solid var(--gp-border-strong);
  border-right: 1px solid var(--gp-border);
  white-space: nowrap;
  position: sticky;
  top: 41px;
  z-index: 15;
}

/* Table Body Rows & Cells */
.gp-table tbody tr {
  background-color: var(--gp-tbody-bg);
  color: var(--gp-text);
}

.gp-table tbody td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--gp-border);
  border-right: 1px solid var(--gp-border);
  white-space: nowrap;
  background-color: inherit;
  transition: background-color 0.12s ease;
}

.gp-table tbody tr:hover {
  background-color: var(--gp-row-hover) !important;
}

.gp-table tbody tr:hover td {
  background-color: var(--gp-row-hover) !important;
}

/* Frozen columns (左侧冻结列) */
.gp-sticky-org,
.gp-sticky-refund,
.gp-sticky-actual,
.gp-sticky-collection,
.gp-sticky-full-paid,
.gp-sticky-enrollment {
  position: sticky;
  z-index: 12;
  background-color: inherit;
}

.gp-sticky-org {
  left: 0;
  font-weight: 600;
  min-width: 250px;
  width: 250px;
  max-width: 250px;
  border-right: 1px solid var(--gp-border-strong) !important;
}

.gp-table tbody .gp-sticky-org {
  text-align: left !important;
}

.gp-sticky-actual {
  left: 695px;
  min-width: 140px;
  width: 140px;
  max-width: 140px;
  font-weight: 700;
  color: #0f766e;
}

.gp-sticky-refund {
  left: 565px;
  min-width: 130px;
  width: 130px;
  max-width: 130px;
}

.gp-sticky-collection {
  left: 250px;
  min-width: 130px;
  width: 130px;
  max-width: 130px;
}

.gp-sticky-full-paid {
  left: 380px;
  min-width: 100px;
  width: 100px;
  max-width: 100px;
}

.gp-sticky-enrollment {
  left: 480px;
  min-width: 85px;
  width: 85px;
  max-width: 85px;
  border-right: 2px solid var(--gp-border-strong) !important;
  box-shadow: 3px 0 6px -3px rgba(0, 0, 0, 0.08);
}

.gp-sticky-month-group {
  position: sticky;
  left: 250px;
  z-index: 20;
  min-width: 315px;
  border-right: 2px solid var(--gp-border-strong) !important;
}

/* Performance columns are opt-in to keep the default report compact. */
.gp-performance-column {
  display: none;
}

.gp-table.gp-show-performance .gp-performance-column {
  display: table-cell;
}

/* Ensure sticky headers use their header row variable */
.gp-table thead tr:first-child th.gp-sticky-org,
.gp-table thead tr:first-child th.gp-sticky-refund,
.gp-table thead tr:first-child th.gp-sticky-actual,
.gp-table thead tr:first-child th.gp-sticky-month-group {
  z-index: 22;
  background-color: var(--gp-th-row1-bg);
}

.gp-table thead tr:nth-child(2) th.gp-sticky-org,
.gp-table thead tr:nth-child(2) th.gp-sticky-refund,
.gp-table thead tr:nth-child(2) th.gp-sticky-actual,
.gp-table thead tr:nth-child(2) th.gp-sticky-collection,
.gp-table thead tr:nth-child(2) th.gp-sticky-full-paid,
.gp-table thead tr:nth-child(2) th.gp-sticky-enrollment {
  z-index: 22;
  background-color: var(--gp-th-row2-bg);
}

/* Hierarchy Tree Row Level Themes */
.gp-tree-level-0 {
  background-color: var(--gp-level0-bg) !important;
  font-weight: 700;
}

.gp-tree-level-0 .gp-sticky-org {
  border-left: 3px solid #3b82f6;
}

.gp-tree-level-1 {
  background-color: var(--gp-level1-bg) !important;
  font-weight: 600;
}

.gp-tree-level-2 {
  background-color: var(--gp-level1-bg) !important;
}

.gp-member-row {
  background-color: var(--gp-level1-bg) !important;
  color: var(--gp-text-muted);
}

.gp-member-row td {
  font-size: 12.5px;
}

/* Hierarchy Tree Cells */
.gp-org-cell {
  padding-left: var(--gp-tree-indent, 16px) !important;
}

.gp-org-cell-content {
  display: flex;
  align-items: center;
  gap: 6px;
}

.gp-org-name {
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--gp-text);
}

.gp-node-count {
  font-size: 12px;
  font-weight: 400;
  color: var(--gp-text-muted);
}

/* Hierarchy Badges (层级标签) */
.gp-node-tag {
  display: inline-flex;
  align-items: center;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.4;
}

.gp-badge-dept {
  background: rgba(37, 99, 235, 0.1);
  color: #2563eb;
}

.gp-badge-team {
  background: rgba(124, 58, 237, 0.1);
  color: #7c3aed;
}

.gp-badge-group {
  background: rgba(16, 185, 129, 0.1);
  color: #059669;
}

.gp-badge-person {
  background: rgba(100, 116, 139, 0.1);
  color: #64748b;
}

/* Tree Toggle Chevron */
.gp-tree-toggle,
.gp-tree-toggle-spacer {
  display: inline-flex;
  width: 18px;
  height: 18px;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.gp-tree-toggle {
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--gp-text-muted);
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.gp-tree-toggle:hover {
  background: rgba(59, 130, 246, 0.12);
  color: #2563eb;
}

.gp-tree-toggle svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.5;
  transition: transform 0.18s ease;
}

.gp-tree-toggle[aria-expanded="true"] svg {
  transform: rotate(90deg);
}

/* Cell Formatting */
.cell-money {
  font-family: var(--font-mono, "JetBrains Mono", "Roboto Mono", monospace);
  font-variant-numeric: tabular-nums;
}

.cell-money.positive {
  color: #059669;
  font-weight: 600;
}

.cell-money.negative {
  color: #e11d48;
  font-weight: 600;
}

.cell-count {
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}

.cell-zero {
  color: var(--gp-zero-color);
  font-weight: 400;
}

/* Total & Refund Summary Rows */
.gp-row-total {
  background-color: var(--gp-total-bg) !important;
  font-weight: 700;
}

.gp-row-total td {
  border-top: 2px solid var(--gp-border-strong);
}

.gp-row-refund {
  background-color: var(--gp-refund-bg) !important;
  font-weight: 700;
}

.gp-empty-state {
  padding: 48px;
  text-align: center;
  color: var(--gp-text-muted);
  font-size: 14px;
}
