:root {
  color-scheme: light;
  --bg: #f3f5f4;
  --surface: #ffffff;
  --surface-subtle: #f7f9f8;
  --ink: #17201c;
  --muted: #66716b;
  --line: #dce2de;
  --line-strong: #c8d1cb;
  --brand: #176b4b;
  --brand-strong: #0e5539;
  --brand-soft: #e7f1ec;
  --contact: #a75b18;
  --contact-soft: #f8eee5;
  --total: #345f82;
  --total-soft: #eaf0f5;
  --danger: #ad3732;
  --shadow: 0 12px 32px rgba(23, 32, 28, 0.08);
  font-family: Inter, "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
  letter-spacing: 0;
}

button, input, select { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.icon-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 28px 20px;
  background: #eef1ef;
}

.auth-panel {
  width: min(100%, 390px);
  padding: 32px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  color: #fff;
  background: var(--brand);
  border-radius: 7px;
  font-weight: 750;
}

.brand-mark-small { width: 32px; height: 32px; font-size: 12px; }
.brand-name { margin: 13px 0 26px; font-weight: 700; }
.auth-panel h1 { margin: 0 0 4px; font-size: 24px; line-height: 1.25; }
.muted { color: var(--muted); }
.auth-panel .muted { margin: 0 0 24px; }

.auth-form, .settings-form { display: grid; gap: 16px; }
label { display: grid; gap: 6px; }
label > span { color: #39453f; font-size: 13px; font-weight: 650; }
label small { color: var(--muted); font-weight: 400; }

input, select {
  width: 100%;
  height: 40px;
  padding: 0 11px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  outline: none;
}

input:focus, select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(23, 107, 75, 0.12);
}

.button, .icon-button, .nav-item {
  border: 0;
  transition: background 150ms ease, border-color 150ms ease, color 150ms ease;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 36px;
  padding: 7px 13px;
  border-radius: 5px;
  font-weight: 650;
}

.button-icon { width: 16px; height: 16px; }
.button-icon-end { margin-right: -3px; }
.button:disabled { cursor: not-allowed; opacity: 0.55; }
.button-full { width: 100%; }
.button-primary { color: #fff; background: var(--brand); }
.button-primary:hover:not(:disabled) { background: var(--brand-strong); }
.button-secondary { color: #294238; background: var(--surface); border: 1px solid var(--line-strong); }
.button-secondary:hover:not(:disabled), .button-quiet:hover:not(:disabled) { background: var(--surface-subtle); }
.button-quiet { color: #45534c; background: transparent; border: 1px solid transparent; }
.button-danger { color: var(--danger); background: transparent; border: 1px solid #e8c8c5; }

.form-error {
  margin: -4px 0 0;
  color: var(--danger);
  font-size: 13px;
}

.app-shell { min-height: 100vh; }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  width: 208px;
  padding: 18px 12px;
  background: var(--surface);
  border-right: 1px solid var(--line);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 8px 22px;
  font-size: 15px;
  font-weight: 750;
}

.primary-nav { display: grid; gap: 3px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 40px;
  padding: 0 11px;
  color: #53605a;
  background: transparent;
  border-radius: 5px;
  text-align: left;
  font-weight: 600;
}

.nav-item:hover { background: var(--surface-subtle); }
.nav-item.is-active { color: var(--brand-strong); background: var(--brand-soft); }
.nav-icon { flex: 0 0 17px; width: 17px; height: 17px; }

.sidebar-footer { margin-top: auto; padding-top: 16px; border-top: 1px solid var(--line); }
.account-brief { display: flex; align-items: center; gap: 10px; padding: 0 7px 12px; min-width: 0; }
.avatar {
  display: grid;
  place-items: center;
  flex: 0 0 34px;
  height: 34px;
  border-radius: 50%;
  background: #e7ece9;
  color: #405048;
  font-weight: 750;
}
.account-copy { display: grid; min-width: 0; }
.account-copy strong, .account-copy small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-copy small { color: var(--muted); }

.workspace { min-height: 100vh; margin-left: 208px; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 8;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 68px;
  padding: 10px 24px;
  background: rgba(255, 255, 255, 0.97);
  border-bottom: 1px solid var(--line);
}

.topbar h1 { margin: 0; font-size: 19px; line-height: 1.25; }
.kicker { margin: 0 0 1px; color: var(--muted); font-size: 12px; }
.topbar-actions { display: flex; align-items: center; gap: 7px; }
.compact-field { min-width: 132px; }
.compact-field input, .compact-field select { height: 34px; }
.icon-button {
  display: grid;
  place-items: center;
  flex: 0 0 34px;
  width: 34px;
  height: 34px;
  padding: 0;
  color: #3b4942;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 5px;
}
.icon-button svg { width: 16px; height: 16px; }
.icon-button:hover { background: var(--surface-subtle); }

.content { width: min(100%, 1480px); margin: 0 auto; padding: 22px 24px 42px; }
.loading-state {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 320px;
  color: var(--muted);
}
.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--line-strong);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.daily-targets {
  display: grid;
  grid-template-columns: 1.18fr 1fr 1fr;
  gap: 12px;
}

.target-card {
  min-width: 0;
  min-height: 144px;
  padding: 17px 18px 15px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 7px;
}

.target-total { border-top: 3px solid var(--total); padding-top: 15px; }
.target-heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; color: var(--muted); font-weight: 650; }
.target-heading small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 400; }
.target-heading svg { flex: 0 0 17px; width: 17px; height: 17px; }
.target-value { display: flex; align-items: baseline; gap: 6px; margin-top: 18px; }
.target-value strong { font-size: 30px; line-height: 1; }
.target-value span { color: var(--muted); }
.target-card > small { display: block; margin-top: 10px; color: var(--muted); font-size: 12px; }
.progress-track {
  width: 100%;
  height: 5px;
  margin-top: 14px;
  overflow: hidden;
  background: #e8ece9;
  border-radius: 3px;
}
.progress-fill { display: block; width: 0; height: 100%; transition: width 250ms ease; }
.progress-green { background: var(--brand); }
.progress-contact { background: var(--contact); }
.progress-total { background: var(--total); }

.work-status {
  display: flex;
  align-items: center;
  gap: 18px;
  min-height: 43px;
  margin-top: 10px;
  padding: 8px 13px;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 13px;
}
.work-status strong { color: var(--ink); font-size: 14px; }
.status-divider { width: 1px; height: 18px; background: var(--line); }

.data-section { margin-top: 22px; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-bottom: 12px; }
.section-heading h2 { margin: 0; font-size: 16px; }
.section-heading p { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.page-section-heading { margin-bottom: 14px; }
.page-section-heading h2 { font-size: 18px; }

.table-wrap {
  width: 100%;
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 7px;
}
table { width: 100%; border-collapse: collapse; }
th, td { padding: 11px 13px; border-bottom: 1px solid #e7ebe8; text-align: left; vertical-align: middle; }
th { color: var(--muted); background: var(--surface-subtle); font-size: 12px; font-weight: 650; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #fbfcfb; }
td { min-width: 90px; }
.member-cell { display: grid; }
.member-cell small { color: var(--muted); }
.inline-progress { display: flex; align-items: center; gap: 8px; min-width: 128px; }
.inline-progress .progress-track { width: 78px; margin: 0; }
.inline-progress small { color: var(--muted); white-space: nowrap; }

.compact-product-list {
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 7px;
}
.compact-product {
  display: grid;
  grid-template-columns: minmax(260px, 1.55fr) minmax(150px, 0.7fr) minmax(122px, auto);
  align-items: center;
  gap: 16px;
  min-height: 68px;
  padding: 9px 12px;
  border-top: 1px solid #e7ebe8;
}
.compact-product:first-child { border-top: 0; }
.compact-product:hover { background: #fbfcfb; }
.compact-product-main, .product-cell { display: flex; align-items: center; gap: 11px; min-width: 0; }
.compact-product-copy, .product-copy { flex: 1; min-width: 0; }
.compact-product-copy strong, .product-title {
  display: block;
  overflow: hidden;
  color: var(--ink);
  text-overflow: ellipsis;
  white-space: nowrap;
}
.compact-product-copy small, .product-meta { display: block; color: var(--muted); }
.product-meta { margin-top: 2px; font-size: 12px; }
.shop-column { min-width: 0; }
.shop-column span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.shop-column small { color: var(--muted); }

.product-thumb-shell {
  position: relative;
  display: grid;
  place-items: center;
  flex: 0 0 46px;
  width: 46px;
  height: 46px;
  overflow: hidden;
  color: #839089;
  background: #edf0ee;
  border: 1px solid #e1e6e3;
  border-radius: 5px;
}
.product-thumb-image { width: 100%; height: 100%; object-fit: cover; }
.product-thumb-placeholder { display: grid; place-items: center; width: 100%; height: 100%; }
.product-thumb-placeholder svg { width: 18px; height: 18px; stroke-width: 1.6; }
.contact-table .product-thumb-shell { flex-basis: 50px; width: 50px; height: 50px; }

.search-field { position: relative; display: block; width: min(310px, 100%); }
.search-field > svg { position: absolute; left: 11px; top: 10px; width: 16px; height: 16px; color: var(--muted); pointer-events: none; }
.search-field input { height: 36px; padding-left: 34px; }
.product-table th, .product-table td { padding: 11px 14px; }
.contact-table th, .contact-table td { padding: 11px 14px; }
.product-table td:first-child { width: 42%; max-width: 520px; }
.contact-table td:first-child { width: 47%; max-width: 560px; }
.product-title { font-weight: 650; }
.actions-column { width: 132px; text-align: right; }
.table-actions { display: flex; justify-content: flex-end; gap: 6px; }
.table-actions .button { min-height: 32px; padding: 5px 9px; font-size: 13px; white-space: nowrap; }
.contact-phone strong { color: #25342d; font-size: 15px; white-space: nowrap; }
.no-link { color: var(--muted); font-size: 12px; white-space: nowrap; }

.split-layout {
  display: grid;
  grid-template-columns: minmax(280px, 0.72fr) minmax(420px, 1.28fr);
  gap: 18px;
  align-items: start;
}
.invite-form-section, .invite-list-section {
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 7px;
}
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.new-invite { display: grid; gap: 11px; margin-top: 17px; padding-top: 16px; border-top: 1px solid var(--line); }
.new-invite p { margin: 2px 0 0; color: #53645b; font-size: 12px; }
.invitation-list { display: grid; }
.invitation-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 12px;
  align-items: center;
  padding: 12px 2px;
  border-top: 1px solid #e7ebe8;
}
.invitation-row:first-child { border-top: 0; }
.invitation-main { min-width: 0; }
.invitation-main strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.invitation-main small { color: var(--muted); }
.status {
  display: inline-flex;
  align-items: center;
  min-height: 23px;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 650;
  white-space: nowrap;
}
.status-active { color: var(--brand-strong); background: var(--brand-soft); }
.status-used { color: var(--total); background: var(--total-soft); }
.status-ended { color: #6a716d; background: #ecefed; }

.empty-state { padding: 62px 20px; color: var(--muted); text-align: center; }
.empty-state strong { color: var(--ink); font-size: 16px; }
.empty-state p { margin: 7px auto 18px; max-width: 440px; }
.inline-empty { padding: 30px 10px; color: var(--muted); text-align: center; }
.collection-empty { display: grid; place-items: center; gap: 6px; min-height: 138px; color: var(--muted); text-align: center; }
.collection-empty img { width: 148px; max-width: 46vw; aspect-ratio: 3 / 2; object-fit: contain; mix-blend-mode: multiply; }
.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 50;
  max-width: min(360px, calc(100vw - 36px));
  padding: 10px 13px;
  color: #fff;
  background: #26342e;
  border-radius: 5px;
  box-shadow: var(--shadow);
}

@media (max-width: 1100px) {
  .daily-targets { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .target-total { grid-column: 1 / -1; }
  .split-layout { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
  body { padding-bottom: 64px; }
  .app-shell { min-height: calc(100vh - 64px); }
  .sidebar {
    position: fixed;
    inset: auto 0 0 0;
    z-index: 20;
    display: block;
    width: 100%;
    height: 64px;
    padding: 5px 6px max(5px, env(safe-area-inset-bottom));
    border: 0;
    border-top: 1px solid var(--line);
  }
  .sidebar-brand, .sidebar-footer { display: none; }
  .primary-nav { display: flex; justify-content: space-around; height: 100%; }
  .nav-item {
    display: grid;
    place-items: center;
    align-content: center;
    gap: 2px;
    width: auto;
    min-width: 76px;
    min-height: 52px;
    padding: 2px 8px;
    font-size: 11px;
    text-align: center;
  }
  .nav-icon { width: 16px; height: 16px; }
  .workspace { margin-left: 0; }
  .topbar { position: static; display: grid; gap: 11px; min-height: 0; padding: 13px 14px; }
  .topbar h1 { font-size: 18px; }
  .topbar-actions { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 34px; width: 100%; }
  .app-shell.is-member .topbar-actions { grid-template-columns: minmax(0, 1fr) 34px; }
  .compact-field { min-width: 0; }
  .content { padding: 14px 12px 28px; }
  .daily-targets { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
  .target-card { min-height: 132px; padding: 14px; }
  .target-total { padding-top: 12px; }
  .target-value { margin-top: 15px; }
  .target-value strong { font-size: 26px; }
  .target-heading small { display: none; }
  .work-status { flex-wrap: wrap; gap: 6px 14px; }
  .status-divider { display: none; }
  .data-section { margin-top: 18px; }
  .section-heading { align-items: flex-start; }
  .compact-product { grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
  .compact-product .shop-column { display: none; }
  .page-section-heading { display: grid; grid-template-columns: minmax(0, 1fr); justify-content: stretch; }
  .search-field { width: 100%; }
  .product-table-wrap, .contact-table-wrap { overflow-x: hidden; }
  .product-table, .contact-table { min-width: 0; }
  .product-table thead, .contact-table thead { display: none; }
  .product-table tbody, .product-table tr, .product-table td,
  .contact-table tbody, .contact-table tr, .contact-table td { display: block; }
  .product-table tr, .contact-table tr { padding: 12px; border-bottom: 1px solid var(--line); }
  .product-table tr:last-child, .contact-table tr:last-child { border-bottom: 0; }
  .product-table td, .contact-table td {
    width: auto !important;
    max-width: none !important;
    min-width: 0;
    padding: 2px 0;
    border: 0;
    overflow-wrap: anywhere;
  }
  .product-table td:nth-child(2) { width: calc(100% - 57px) !important; margin: 7px 0 2px 57px; }
  .product-table td:nth-child(3), .product-table td:nth-child(4),
  .contact-table td:nth-child(3), .contact-table td:nth-child(4) {
    display: inline;
    margin-right: 7px;
    color: var(--muted);
    font-size: 12px;
  }
  .product-table td:nth-child(3)::before { content: "成员 "; }
  .product-table td:nth-child(4)::before { content: " · "; }
  .contact-table td:nth-child(3)::before { content: "成员 "; }
  .contact-table td:nth-child(4)::before { content: " · "; }
  .product-table td:last-child, .contact-table td:last-child { padding-top: 10px; }
  .contact-table .contact-phone { width: calc(100% - 61px) !important; margin: 8px 0 4px 61px; font-size: 16px; }
  .table-actions { justify-content: flex-start; }
  .invitation-row { grid-template-columns: minmax(0, 1fr) auto; }
  .invitation-row .button { grid-column: 1 / -1; width: 100%; }
}

@media (max-width: 390px) {
  .auth-panel { padding: 26px 21px; }
  .daily-targets { grid-template-columns: 1fr; }
  .target-total { grid-column: auto; }
  .target-card { min-height: 124px; }
  .form-grid { grid-template-columns: 1fr; }
  .nav-item { min-width: 62px; padding-inline: 5px; }
  .compact-product { grid-template-columns: minmax(0, 1fr) 36px; }
  .compact-product .button { width: 34px; min-width: 34px; padding: 0; }
  .compact-product .button span { display: none; }
}

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