:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-strong: #f0f4f8;
  --text: #17202a;
  --muted: #657182;
  --line: #dce3ea;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --ok: #15803d;
  --warn: #b45309;
  --danger: #b91c1c;
  --info: #0369a1;
  --shadow: 0 16px 40px rgba(23, 32, 42, 0.08);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
  border-radius: 6px;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  min-height: 36px;
  padding: 0 14px;
}

button:hover {
  background: var(--primary-dark);
}

button.secondary {
  background: var(--surface-strong);
  color: var(--text);
  border: 1px solid var(--line);
}

button.secondary:hover {
  background: #e7edf4;
}

button.danger {
  background: var(--danger);
}

button.danger:hover {
  background: #991b1b;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

input,
select,
textarea {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 8px 10px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
}

.sidebar {
  background: #111827;
  color: #f9fafb;
  padding: 18px 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 8px 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.brand-logo {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  object-fit: cover;
  display: block;
  flex: 0 0 auto;
}

.brand strong,
.brand span {
  display: block;
}

.brand span {
  color: #aab2c0;
  font-size: 12px;
}

.nav-list {
  display: grid;
  gap: 6px;
  margin-top: 18px;
}

.nav-item {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: transparent;
  color: #dbe3ef;
  text-align: left;
  border-radius: 6px;
}

.nav-item:hover,
.nav-item.is-active {
  background: rgba(255, 255, 255, 0.12);
}

.nav-item span {
  color: #9ca3af;
  font-size: 12px;
}

.workspace {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  min-height: 76px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) minmax(320px, 460px) auto;
  align-items: center;
  gap: 18px;
  padding: 16px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.topbar h1,
.topbar p {
  margin: 0;
}

.topbar h1 {
  font-size: 22px;
}

.topbar p {
  color: var(--muted);
}

.icon-button {
  width: 38px;
  padding: 0;
  display: none;
}

.api-form {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 8px;
}

.api-form label {
  color: var(--muted);
}

.api-status {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #fee2e2;
  color: var(--danger);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.api-status.is-online {
  background: #dcfce7;
  color: var(--ok);
}

.api-status.is-preview {
  background: #fef3c7;
  color: var(--warn);
}

.admin-session {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: flex-end;
  min-width: 150px;
}

.admin-session span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
  white-space: nowrap;
}

.login-panel {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 32px;
}

.login-form {
  width: min(420px, 100%);
  display: grid;
  gap: 14px;
  padding: 28px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.login-form h2,
.login-form p {
  margin: 0;
}

.login-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
}

.content {
  padding: 24px;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(220px, 320px);
  gap: 16px;
  align-items: end;
  margin-bottom: 18px;
}

.segmented {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.segmented button {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
}

.segmented button.is-active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.search-tools {
  display: grid;
  gap: 6px;
  justify-self: end;
  width: min(420px, 100%);
  min-width: 280px;
}

.search-control {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 40px;
  align-items: center;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.search-control.has-filter {
  grid-template-columns: minmax(0, 1fr) 40px 40px;
}

.search-control input {
  min-height: 40px;
  border: 0;
  border-radius: 0;
  background: transparent;
  padding: 0 12px;
}

.search-control input:focus {
  outline: none;
}

.search-control:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.icon-action {
  width: 40px;
  min-height: 40px;
  display: grid;
  place-items: center;
  padding: 0;
  border-left: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  color: var(--muted);
}

.icon-action:hover,
.icon-action:focus-visible {
  background: var(--surface-strong);
  color: var(--text);
}

.icon-action.is-active {
  background: rgba(37, 99, 235, 0.12);
  color: var(--primary);
}

.icon-action svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.advanced-filter-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  flex-wrap: wrap;
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
}

.advanced-filter-bar span {
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.advanced-filter-bar small {
  color: var(--muted);
  white-space: nowrap;
}

.advanced-filter-bar .summary-clear {
  width: 22px;
  min-height: 22px;
  padding: 0;
  border-radius: 999px;
  background: var(--surface-strong);
  color: var(--muted);
  font-size: 16px;
  line-height: 1;
}

.advanced-filter-bar .summary-clear:hover {
  background: var(--line);
  color: var(--text);
}

.report-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
}

.report-range {
  min-width: 0;
}

.report-date-fields {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
}

.report-date-fields input {
  width: 148px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.metric {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}

.metric span {
  display: block;
  color: var(--muted);
}

.metric strong {
  display: block;
  margin-top: 6px;
  font-size: 24px;
}

.chart-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.chart-card {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

.chart-card.is-wide {
  grid-column: span 2;
}

.chart-card.is-trend {
  grid-column: 1 / -1;
}

.chart-card header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.chart-card h3 {
  margin: 0;
  font-size: 15px;
}

.chart-card header span,
.chart-legend {
  color: var(--muted);
  font-size: 12px;
}

.report-chart {
  display: block;
  width: 100%;
  height: auto;
  min-height: 190px;
}

.report-chart text {
  fill: var(--muted);
  font-size: 11px;
}

.trend-panel {
  display: grid;
  gap: 8px;
}

.trend-panel + .trend-panel {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.trend-panel-title {
  display: flex;
  align-items: baseline;
  justify-content: flex-end;
  gap: 12px;
  color: var(--text);
  font-size: 13px;
}

.trend-panel-title span {
  color: var(--muted);
  font-size: 12px;
}

.trend-chart {
  min-height: 220px;
  overflow: visible;
  cursor: crosshair;
}

.trend-axis text {
  fill: color-mix(in srgb, var(--muted) 86%, transparent);
}

.trend-grid-line,
.trend-axis-line,
.trend-line,
.trend-crosshair {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.trend-grid-line {
  stroke: color-mix(in srgb, var(--line) 78%, transparent);
  stroke-width: 1;
}

.trend-axis-line {
  stroke: color-mix(in srgb, var(--muted) 58%, transparent);
  stroke-width: 1;
}

.trend-line {
  stroke-width: 2.2;
}

.trend-chart.orders .trend-line,
.trend-chart.orders .trend-dot {
  stroke: #6e7681;
}

.trend-chart.revenue .trend-line,
.trend-chart.revenue .trend-dot {
  stroke: #58a6ff;
}

.trend-hitbox {
  fill: transparent;
}

.trend-crosshair,
.trend-dot,
.trend-tooltip {
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms ease;
}

.trend-crosshair {
  stroke: color-mix(in srgb, var(--muted) 78%, transparent);
  stroke-dasharray: 4 5;
  stroke-width: 1;
}

.trend-dot {
  fill: var(--surface);
  stroke-width: 2.2;
}

.trend-tooltip rect {
  fill: color-mix(in srgb, var(--surface) 96%, black);
  stroke: var(--line);
  filter: drop-shadow(0 12px 24px rgb(0 0 0 / 0.22));
}

.trend-tooltip text {
  fill: var(--text);
  font-size: 11px;
}

.trend-hover-point:hover .trend-crosshair,
.trend-hover-point:hover .trend-dot,
.trend-hover-point:hover .trend-tooltip {
  opacity: 1;
}

.bar-list {
  display: grid;
  gap: 10px;
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(70px, 1fr) minmax(80px, 1.3fr) auto;
  gap: 8px;
  align-items: center;
  min-width: 0;
  font-size: 12px;
}

.bar-row span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar-row strong {
  white-space: nowrap;
}

.bar-track {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-strong);
}

.bar-track i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--primary);
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.panel-header h2 {
  margin: 0;
  font-size: 16px;
}

.panel-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.panel-icon-action {
  border-radius: 6px;
}

.export-options {
  display: grid;
  gap: 12px;
}

.export-options button {
  display: grid;
  gap: 4px;
  min-height: 74px;
  padding: 14px;
  text-align: left;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
}

.export-options button:hover {
  border-color: var(--primary);
  background: var(--surface-strong);
}

.export-options span {
  color: var(--muted);
  font-size: 12px;
}

.export-inline {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-bottom: 12px;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 920px;
}

th,
td {
  text-align: left;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

th {
  white-space: nowrap;
  color: var(--muted);
  font-weight: 600;
  background: #fafbfd;
}

tr:last-child td {
  border-bottom: 0;
}

.status {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.status.ok {
  color: var(--ok);
  background: #dcfce7;
}

.status.warn {
  color: var(--warn);
  background: #fef3c7;
}

.status.danger {
  color: var(--danger);
  background: #fee2e2;
}

.status.info {
  color: var(--info);
  background: #e0f2fe;
}

.muted {
  color: var(--muted);
  font-size: 12px;
}

.actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.actions button {
  min-height: 32px;
  padding: 0 10px;
}

.audit-summary {
  max-width: 340px;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.audit-payload {
  margin-top: 8px;
  white-space: pre-wrap;
}

.coach-table-cell {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 180px;
}

.coach-table-cell strong,
.coach-table-cell span {
  display: block;
}

.coach-table-cell span {
  color: var(--muted);
  font-size: 12px;
}

.coach-thumb {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  border-radius: 999px;
  object-fit: cover;
  background: #e8eef5;
}

.empty {
  padding: 36px 16px;
  text-align: center;
  color: var(--muted);
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  width: min(360px, calc(100vw - 40px));
  background: #111827;
  color: #fff;
  border-radius: 8px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
}

.drawer-backdrop[hidden] {
  display: none;
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  justify-content: flex-end;
  background: rgba(17, 24, 39, 0.34);
}

.drawer-panel {
  width: min(560px, 100vw);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  box-shadow: -20px 0 50px rgba(17, 24, 39, 0.18);
}

.drawer-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  align-items: start;
  padding: 20px 22px 16px;
  border-bottom: 1px solid var(--line);
}

.drawer-header h2,
.drawer-header p {
  margin: 0;
}

.drawer-header h2 {
  margin-top: 4px;
  font-size: 20px;
}

.drawer-header p {
  margin-top: 4px;
  color: var(--muted);
}

.drawer-kicker {
  color: var(--primary);
  font-size: 12px;
  font-weight: 700;
}

.drawer-close {
  display: grid;
  place-items: center;
  background: var(--surface-strong);
  color: var(--text);
  border: 1px solid var(--line);
}

.drawer-body {
  min-height: 0;
  overflow-y: auto;
  padding: 20px 22px 24px;
}

.drawer-body .metric-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.drawer-form {
  display: grid;
  gap: 14px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.form-field {
  display: grid;
  gap: 6px;
}

.form-field.is-wide {
  grid-column: 1 / -1;
}

.form-field label {
  color: var(--muted);
  font-weight: 600;
}

.file-upload {
  display: grid;
  grid-template-columns: 82px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
}

.file-preview {
  display: grid;
  place-items: center;
  width: 82px;
  height: 82px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: #fafbfd;
  overflow: hidden;
}

.file-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.file-preview span {
  font-size: 12px;
}

.form-help {
  color: var(--muted);
  font-size: 12px;
}

.checkbox-field {
  min-height: 36px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  font-weight: 500;
}

.checkbox-field input {
  width: 16px;
  min-height: 16px;
  accent-color: var(--primary);
}

.drawer-actions {
  position: sticky;
  bottom: -24px;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin: 8px -22px -24px;
  padding: 14px 22px;
  background: var(--surface);
  border-top: 1px solid var(--line);
}

.detail-list {
  display: grid;
  grid-template-columns: 128px minmax(0, 1fr);
  gap: 10px 14px;
  margin-bottom: 18px;
}

.detail-list dt {
  color: var(--muted);
  font-weight: 600;
}

.detail-list dd {
  margin: 0;
  min-width: 0;
  overflow-wrap: anywhere;
}

.detail-json {
  max-height: 340px;
  overflow: auto;
  margin: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0f172a;
  color: #e2e8f0;
  font-size: 12px;
  line-height: 1.55;
}

@media (max-width: 1200px) {
  .metric-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .chart-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 920px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    display: none;
  }

  .sidebar.is-open {
    display: block;
  }

  .topbar {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .api-form,
  .admin-session {
    grid-column: 1 / -1;
  }

  .api-form {
    grid-template-columns: auto minmax(0, 1fr) auto;
  }

  .admin-session {
    justify-content: flex-start;
  }

  .api-status {
    grid-column: 2 / -1;
    justify-self: start;
  }

  .icon-button {
    display: grid;
    place-items: center;
  }

  .toolbar,
  .metric-grid {
    grid-template-columns: 1fr;
  }

  .report-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .report-date-fields {
    flex-wrap: wrap;
  }

  .chart-grid {
    grid-template-columns: 1fr;
  }

  .chart-card.is-wide {
    grid-column: auto;
  }

  .search-tools {
    justify-self: stretch;
    width: 100%;
    min-width: 0;
  }
}

@media (max-width: 560px) {
  .content,
  .topbar,
  .login-panel {
    padding: 16px;
  }

  .panel-header,
  .actions {
    align-items: stretch;
    flex-direction: column;
  }

  .actions button {
    width: 100%;
  }

  .drawer-header,
  .drawer-body {
    padding-left: 16px;
    padding-right: 16px;
  }

  .form-grid,
  .detail-list,
  .drawer-body .metric-grid {
    grid-template-columns: 1fr;
  }

  .drawer-actions {
    margin-left: -16px;
    margin-right: -16px;
    padding-left: 16px;
    padding-right: 16px;
  }
}
