:root {
  color-scheme: light;
  --page: #f4f5f7;
  --surface: #ffffff;
  --surface-muted: #f8f9fa;
  --ink: #1d232a;
  --muted: #68717d;
  --line: #dfe3e8;
  --accent: #c84f2d;
  --accent-soft: #fff0ea;
  --success: #39705b;
  --radius: 14px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }

body {
  min-height: 100dvh;
  margin: 0;
  background: var(--page);
  color: var(--ink);
}

button, input { font: inherit; }

button {
  min-height: 44px;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 0.65rem 0.95rem;
  background: var(--ink);
  color: white;
  cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease, transform 140ms ease;
}

button:hover { background: #313943; }
button:active { transform: translateY(1px); }
button:focus-visible, input:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 32%, transparent);
  outline-offset: 2px;
}

.ghost-button {
  border-color: var(--line);
  background: var(--surface);
  color: var(--ink);
}

.ghost-button:hover { background: var(--surface-muted); }

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 2rem;
  width: calc(100% - 2.5rem);
  max-width: 1420px;
  min-width: 0;
  margin: 0 auto;
  padding: 1.8rem 0 1.3rem;
}

.eyebrow {
  margin: 0 0 0.35rem;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
}

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0.35rem; font-size: clamp(1.8rem, 3vw, 2.5rem); letter-spacing: -0.04em; }
.subtitle, .section-heading p { margin-bottom: 0; color: var(--muted); }

.topbar-actions { display: flex; align-items: center; gap: 0.65rem; }
.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0 0.75rem;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}
.status-pill.ok { color: var(--success); }

.dashboard-shell {
  display: grid;
  gap: 1rem;
  width: calc(100% - 2.5rem);
  max-width: 1420px;
  min-width: 0;
  margin: 0 auto;
  padding-bottom: 3rem;
}

.period-section, .detail-section {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.period-section { padding: 0.9rem; }
.period-buttons { display: flex; gap: 0.45rem; overflow-x: auto; scrollbar-width: thin; }
.period-buttons button {
  flex: 0 0 auto;
  min-height: 40px;
  border-color: var(--line);
  background: var(--surface);
  color: var(--ink);
}
.period-buttons button.active { border-color: var(--accent); background: var(--accent); color: white; }

.custom-period {
  display: flex;
  align-items: end;
  gap: 0.7rem;
  margin-top: 0.8rem;
  border-top: 1px solid var(--line);
  padding-top: 0.8rem;
}
.custom-period[hidden] { display: none; }
.custom-period label, .login-form label {
  display: grid;
  gap: 0.35rem;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
}
input {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0 0.75rem;
  background: var(--surface);
  color: var(--ink);
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}
.metric-item { min-width: 0; border-right: 1px solid var(--line); padding: 1rem; }
.metric-item:last-child { border-right: 0; }
.metric-item span { display: block; color: var(--muted); font-size: 0.8rem; font-weight: 700; }
.metric-item strong {
  display: block;
  margin-top: 0.45rem;
  font-size: clamp(1.25rem, 2vw, 1.85rem);
  letter-spacing: -0.035em;
  white-space: nowrap;
}

.detail-section { overflow: hidden; }
.section-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
  border-bottom: 1px solid var(--line);
  padding: 1rem 1.1rem;
}
.section-heading h2 { margin-bottom: 0.25rem; font-size: 1.15rem; }
.section-heading p { font-size: 0.88rem; }
.data-meta { display: grid; gap: 0.2rem; text-align: right; color: var(--muted); font-size: 0.78rem; }

.nutritionist-group + .nutritionist-group { border-top: 1px solid var(--line); }
.nutritionist-summary {
  display: grid;
  grid-template-columns: minmax(150px, 0.8fr) minmax(560px, 2.2fr);
  width: 100%;
  border: 0;
  border-radius: 0;
  padding: 0.95rem 1.1rem;
  background: var(--surface);
  color: var(--ink);
  text-align: left;
}
.nutritionist-summary:hover { background: var(--surface-muted); }
.nutritionist-identity { display: flex; align-items: center; gap: 0.65rem; font-size: 1rem; }
.disclosure { width: 1rem; color: var(--accent); font-size: 1.25rem; }
.nutritionist-stats { display: grid; grid-template-columns: repeat(6, minmax(72px, 1fr)); gap: 0.75rem; }
.summary-stat { display: grid; gap: 0.2rem; min-width: 0; }
.summary-stat small { color: var(--muted); font-size: 0.72rem; }
.summary-stat strong { overflow: hidden; font-size: 0.88rem; text-overflow: ellipsis; white-space: nowrap; }
.summary-stat.emphasize strong { color: var(--accent); }
.nutritionist-body { border-top: 1px solid var(--line); padding: 0.85rem; background: var(--surface-muted); }

.customer-card { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.customer-card + .customer-card { margin-top: 0.75rem; }
.customer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  border-bottom: 1px solid var(--line);
  padding: 0.85rem 1rem;
}
.customer-identity { display: grid; gap: 0.2rem; }
.customer-identity strong { font-size: 1rem; }
.customer-identity span { color: var(--muted); font-size: 0.84rem; }
.customer-history { display: flex; gap: 1.5rem; }

.order-list { padding: 0 1rem; }
.order-card { padding: 0.9rem 0; }
.order-card + .order-card { border-top: 1px solid var(--line); }
.order-header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.order-primary { display: flex; align-items: center; gap: 0.65rem; flex-wrap: wrap; }
.order-primary > span:not(.order-badge) { color: var(--muted); font-size: 0.8rem; }
.order-badge { border-radius: 6px; padding: 0.22rem 0.45rem; font-size: 0.72rem; font-weight: 800; }
.order-badge.first { background: var(--accent-soft); color: var(--accent); }
.order-badge.repeat { background: #edf2f7; color: #4d5967; }
.order-badge.unknown { background: #f1f1f1; color: var(--muted); }
.order-amount { color: var(--accent); }

.commission-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.55rem; margin-top: 0.7rem; }
.commission-line {
  display: grid;
  grid-template-columns: auto auto 1fr auto;
  gap: 0.55rem;
  align-items: center;
  border-radius: 9px;
  padding: 0.55rem 0.65rem;
  background: var(--surface-muted);
  color: var(--muted);
  font-size: 0.78rem;
}
.commission-line strong { color: var(--ink); }
.settlement { text-align: right; }

.product-list { margin-top: 0.65rem; border-top: 1px dashed var(--line); }
.product-row {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 70px 100px 100px;
  gap: 0.75rem;
  align-items: center;
  padding: 0.55rem 0;
  color: var(--muted);
  font-size: 0.82rem;
  text-align: right;
}
.product-row + .product-row { border-top: 1px solid #edf0f2; }
.product-name { display: grid; gap: 0.12rem; text-align: left; color: var(--ink); }
.product-name small { color: var(--muted); }

.empty-state, .inline-loading {
  display: grid;
  min-height: 120px;
  place-items: center;
  gap: 0.7rem;
  color: var(--muted);
  text-align: center;
}
.load-more { display: block; margin: 0.8rem auto 0; background: var(--accent); }
.skeleton-row { height: 72px; margin: 1rem; border-radius: 10px; background: linear-gradient(90deg, #edf0f2, #f8f9fa, #edf0f2); background-size: 200% 100%; animation: shimmer 1.2s linear infinite; }
.skeleton-row.short { width: 64%; }
@keyframes shimmer { to { background-position: -200% 0; } }

.toast {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 10;
  max-width: min(420px, calc(100% - 2rem));
  border-radius: 10px;
  padding: 0.8rem 1rem;
  background: var(--ink);
  color: white;
  box-shadow: 0 12px 36px rgb(25 30 35 / 18%);
}

.login-body { display: grid; min-height: 100dvh; place-items: center; padding: 1.25rem; }
.login-card { width: min(100%, 420px); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.6rem; background: var(--surface); box-shadow: 0 20px 50px rgb(25 30 35 / 8%); }
.brand-mark { display: inline-flex; margin-bottom: 1rem; border-radius: 8px; padding: 0.4rem 0.6rem; background: var(--accent-soft); color: var(--accent); font-weight: 800; }
.login-card p { color: var(--muted); }
.login-form { display: grid; gap: 0.85rem; margin-top: 1.2rem; }
.login-error { color: #9f3524 !important; font-weight: 700; }

@media (max-width: 1100px) {
  .metric-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .metric-item:nth-child(3) { border-right: 0; }
  .metric-item:nth-child(-n + 3) { border-bottom: 1px solid var(--line); }
  .nutritionist-summary { grid-template-columns: 1fr; gap: 0.75rem; }
  .nutritionist-stats { padding-left: 1.65rem; }
  .commission-grid { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .topbar, .dashboard-shell {
    width: calc(100% - 1rem);
    max-width: 1420px;
    min-width: 0;
  }
  .period-section, .metric-grid, .detail-section { min-width: 0; max-width: 100%; }
  .topbar { align-items: flex-start; padding-top: 1rem; }
  .subtitle, .status-pill { display: none; }
  .topbar-actions { align-self: center; }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric-item, .metric-item:nth-child(3) { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
  .metric-item:nth-child(even) { border-right: 0; }
  .metric-item:nth-last-child(-n + 2) { border-bottom: 0; }
  .section-heading, .customer-header { align-items: flex-start; flex-direction: column; }
  .data-meta { text-align: left; }
  .nutritionist-summary { padding: 0.85rem; }
  .nutritionist-stats { grid-template-columns: repeat(3, 1fr); padding-left: 1.65rem; }
  .nutritionist-body { padding: 0.5rem; }
  .customer-history { gap: 1rem; }
  .order-list { padding: 0 0.75rem; }
  .commission-line { grid-template-columns: auto auto; }
  .commission-line .settlement { text-align: left; }
  .product-list { overflow-x: auto; }
  .product-row { min-width: 610px; }
  .custom-period { align-items: stretch; flex-direction: column; }
  .custom-period input { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}


/* shared-portal-theme */
:root {
  --page: var(--color-page);
  --surface: var(--color-surface);
  --surface-muted: #f8f9fb;
  --ink: var(--color-text);
  --muted: var(--color-muted);
  --line: var(--color-border);
  --accent: var(--color-primary);
  --accent-soft: var(--color-primary-soft);
  --success: var(--color-success);
  --radius: var(--radius-card);
  font-family: var(--font-ui);
}

body { font-family: var(--font-ui); background: var(--color-page); color: var(--color-text); }
.portal-back-link {
  height: 36px;
  padding: 0 11px;
  display: inline-flex;
  align-items: center;
  color: var(--color-primary-strong);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-control);
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
}
.portal-back-link:hover { background: var(--color-primary-soft); border-color: #9bb4ef; }
.portal-back-link:focus-visible { outline: 0; box-shadow: var(--focus-ring); }
button:focus-visible, select:focus-visible, input:focus-visible, a:focus-visible { outline: 0; box-shadow: var(--focus-ring); }
