:root {
  color-scheme: light;
  --bg: #f7f8f6;
  --surface: #ffffff;
  --surface-2: #eef6f3;
  --ink: #182321;
  --muted: #66736f;
  --line: #dce5e1;
  --accent: #0f766e;
  --accent-soft: #d9f2ee;
  --warn: #b45309;
  --danger: #b91c1c;
  --ok: #15803d;
  --shadow: 0 10px 30px rgba(23, 36, 33, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.app-shell {
  width: min(1040px, 100%);
  margin: 0 auto;
  padding: calc(14px + env(safe-area-inset-top)) 12px calc(88px + env(safe-area-inset-bottom));
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: -14px -12px 10px;
  padding: calc(14px + env(safe-area-inset-top)) 14px 12px;
  background: rgba(247, 248, 246, 0.94);
  border-bottom: 1px solid rgba(220, 229, 225, 0.7);
  backdrop-filter: blur(14px);
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 20px;
  line-height: 1.15;
}

h2 {
  font-size: 16px;
  line-height: 1.25;
}

h3 {
  font-size: 15px;
  line-height: 1.25;
}

.readonly-badge {
  flex: 0 0 auto;
  padding: 7px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 13px;
  font-weight: 800;
}

.readonly-badge.ok {
  background: #dcfce7;
  color: var(--ok);
}

.readonly-badge.info {
  background: #e0f2fe;
  color: #0369a1;
}

.readonly-badge.warn {
  background: #ffedd5;
  color: var(--warn);
}

.readonly-badge.danger {
  background: #fee2e2;
  color: var(--danger);
}

.tabbar {
  position: sticky;
  top: calc(61px + env(safe-area-inset-top));
  z-index: 19;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
  margin: 0 0 12px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
}

.tab,
.segment,
.icon-button,
.back-button,
.search-row button {
  min-height: 38px;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
}

.tab {
  min-width: 0;
  padding: 0 4px;
  font-size: 13px;
}

.tab.is-active,
.segment.is-active,
.search-row button {
  background: var(--accent);
  color: #fff;
}

.content {
  display: block;
}

#view-detail,
#view-customer-detail {
  max-width: 760px;
  margin: 0 auto;
}

.view {
  display: none;
}

.view.is-active {
  display: block;
}

.status-line {
  margin: 6px 2px 12px;
  color: var(--muted);
  font-size: 13px;
}

.sync-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 54px;
  margin: 0 0 12px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  background: var(--surface);
}

.sync-strip > div {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.sync-strip strong {
  font-size: 13px;
}

.sync-strip span {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.sync-strip button {
  flex: 0 0 auto;
  min-height: 36px;
  padding: 0 11px;
  border-radius: 7px;
  background: var(--surface-2);
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
}

.sync-strip button:disabled {
  cursor: wait;
  opacity: 0.55;
}

.sync-strip.is-offline {
  border-left-color: var(--warn);
  background: #fffaf4;
}

.sync-strip.is-error {
  border-left-color: var(--danger);
  background: #fff7f7;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.metric {
  min-height: 96px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.metric span {
  color: var(--muted);
  font-size: 12px;
}

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 22px;
  line-height: 1.1;
}

.metric em {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
}

.panel {
  margin-bottom: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.icon-button {
  min-width: 54px;
  padding: 0 10px;
  background: var(--surface-2);
  color: var(--accent);
}

.alert-list,
.timeline,
.compact-list,
.order-list,
.customer-list {
  display: grid;
  gap: 8px;
}

.order-list.is-grouped {
  gap: 14px;
  grid-template-columns: 1fr;
}

.order-status-line {
  margin-top: -2px;
}

.customer-order-group {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.customer-order-group:first-child {
  border-top: 1px solid var(--line);
}

.customer-order-group summary {
  list-style: none;
}

.customer-order-group summary::-webkit-details-marker {
  display: none;
}

.customer-group-summary {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 0 0 10px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}

.customer-group-summary > div:first-child {
  min-width: 0;
  flex: 1 1 auto;
}

.group-money {
  flex: 0 0 auto;
  display: grid;
  gap: 3px;
  min-width: 128px;
  text-align: right;
}

.group-money strong,
.group-money span {
  font-variant-numeric: tabular-nums;
}

.group-money strong {
  color: var(--ink);
  font-size: 14px;
}

.group-money span {
  color: var(--muted);
  font-size: 12px;
}

.customer-profit {
  flex: 0 0 auto;
  display: grid;
  gap: 2px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.customer-profit span {
  color: var(--muted);
  font-size: 11px;
}

.customer-profit strong {
  font-size: 14px;
}

.customer-group-body {
  display: grid;
  gap: 10px;
}

.empty {
  padding: 18px 10px;
  color: var(--muted);
  text-align: center;
}

.alert-item,
.activity,
.compact-item,
.order-card,
.customer-card {
  display: grid;
  gap: 6px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.alert-item {
  border-left: 4px solid var(--warn);
}

.alert-item,
.order-card a,
.customer-card a {
  color: inherit;
  text-decoration: none;
}

.activity {
  border-left: 4px solid var(--accent);
}

.muted,
.meta {
  color: var(--muted);
  font-size: 12px;
}

.money {
  font-variant-numeric: tabular-nums;
  font-weight: 800;
}

.money.ok {
  color: var(--ok);
}

.money.warn {
  color: var(--warn);
}

.money.danger {
  color: var(--danger);
}

.search-row {
  display: grid;
  grid-template-columns: 1fr 72px;
  gap: 8px;
  margin-bottom: 10px;
}

.search-row input {
  min-width: 0;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 0 12px;
  outline: none;
}

.search-row input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.16);
}

.segmented {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 8px;
  margin-bottom: 4px;
}

.segment {
  flex: 0 0 auto;
  min-width: 70px;
  padding: 0 10px;
  border: 1px solid var(--line);
  background: #fff;
}

@media (max-width: 600px) {
  .order-filter-segments,
  .business-filter-segments {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    overflow: visible;
  }

  .order-filter-segments .segment,
  .business-filter-segments .segment {
    width: 100%;
    min-width: 0;
  }
}

.order-card {
  text-align: left;
}

.order-card a {
  display: grid;
  gap: 8px;
  width: 100%;
  padding: 0;
  background: transparent;
  color: inherit;
  text-align: left;
}

.order-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.order-card-head > div:first-child {
  min-width: 0;
}

.order-card-head .money {
  flex: 0 0 auto;
  max-width: 46%;
  overflow-wrap: anywhere;
  text-align: right;
}

.customer-card a {
  display: grid;
  gap: 6px;
  width: 100%;
  padding: 0;
  background: transparent;
  color: inherit;
  text-align: left;
}

.customer-card:focus-within,
.order-card:focus-within {
  border-color: rgba(15, 118, 110, 0.45);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}

.order-head,
.customer-head,
.detail-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
}

.code {
  color: var(--accent);
  font-weight: 900;
}

.pill-row {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 7px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.pill.ok {
  background: #dcfce7;
  color: var(--ok);
}

.pill.info {
  background: #e0f2fe;
  color: #0369a1;
}

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

.pill.danger {
  background: #fee2e2;
  color: var(--danger);
}

.line-summary {
  color: #31403c;
  font-size: 13px;
  line-height: 1.45;
}

.order-mini-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.order-mini-stat {
  min-width: 0;
  padding: 7px 8px;
  border-radius: 8px;
  background: var(--surface-2);
}

.order-mini-stat span {
  display: block;
  color: var(--muted);
  font-size: 11px;
}

.order-mini-stat strong {
  display: block;
  margin-top: 2px;
  overflow-wrap: anywhere;
  font-size: 12px;
  line-height: 1.25;
}

.back-button {
  margin-bottom: 10px;
  padding: 0 12px;
  background: var(--surface-2);
  color: var(--accent);
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.order-detail-panel {
  display: grid;
  gap: 12px;
}

.order-detail-head {
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.order-detail-head > div:first-child {
  min-width: 0;
}

.detail-money-grid,
.detail-status-grid,
.line-stat-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.detail-metric,
.status-tile,
.line-stat {
  min-width: 0;
  padding: 10px;
  border-radius: 8px;
  background: var(--surface-2);
}

.detail-metric span,
.status-tile span,
.line-stat span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.detail-metric strong,
.status-tile strong,
.line-stat strong {
  display: block;
  margin-top: 4px;
  overflow-wrap: anywhere;
  font-size: 15px;
  line-height: 1.25;
}

.detail-metric.primary {
  background: #e7f5f2;
}

.detail-metric.ok {
  background: #ecfdf3;
}

.detail-metric.warn {
  background: #fff7ed;
}

.status-tile.ok {
  background: #ecfdf3;
}

.status-tile.info {
  background: #eff6ff;
}

.status-tile.warn {
  background: #fff7ed;
}

.status-tile.danger {
  background: #fef2f2;
}

.detail-kv {
  padding: 9px;
  border-radius: 8px;
  background: var(--surface-2);
}

.detail-kv span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.detail-kv strong {
  display: block;
  margin-top: 4px;
  font-size: 14px;
  overflow-wrap: anywhere;
}

.line-table {
  display: grid;
  gap: 8px;
}

.line-card {
  display: grid;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.line-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.line-card-title {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.line-card-title strong {
  overflow-wrap: anywhere;
  font-size: 15px;
}

.line-card-title span {
  color: var(--muted);
  font-size: 12px;
}

.note-list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.note-block {
  padding: 10px;
  border-left: 3px solid var(--accent);
  background: var(--surface-2);
}

.note-block span {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.note-block p {
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  font-size: 12px;
  line-height: 1.55;
}

.module-metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.module-metric {
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
}

.module-metric span {
  display: block;
  color: var(--muted);
  font-size: 11px;
}

.module-metric strong {
  display: block;
  margin-top: 4px;
  overflow-wrap: anywhere;
  font-size: 15px;
}

.module-metric.ok strong {
  color: var(--ok);
}

.module-metric.warn strong {
  color: var(--warn);
}

.record-list {
  display: grid;
  gap: 10px;
}

.record-group {
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.record-group > summary {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  min-height: 64px;
  padding: 11px;
  cursor: pointer;
  list-style: none;
}

.record-group > summary::-webkit-details-marker {
  display: none;
}

.record-group > summary > div:first-child {
  display: grid;
  min-width: 0;
  gap: 2px;
}

.record-group > summary strong,
.record-group > summary span,
.row-record strong,
.row-record span {
  overflow-wrap: anywhere;
}

.record-group > summary span,
.row-record span {
  color: var(--muted);
  font-size: 11px;
}

.record-body {
  display: grid;
  gap: 7px;
  padding: 0 11px 11px;
  border-top: 1px solid var(--line);
}

.row-record {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 9px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
}

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

.row-record > div:first-child {
  display: grid;
  min-width: 0;
  gap: 3px;
}

.record-money {
  display: grid;
  flex: 0 0 min(46%, 178px);
  gap: 3px;
  min-width: 0;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.record-money strong,
.record-money span {
  overflow-wrap: anywhere;
}

.sub-records {
  display: grid;
  gap: 6px;
  margin-top: 7px;
}

.sub-records > div {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 2px 8px;
  padding: 8px;
  background: var(--surface-2);
}

.sub-records span,
.sub-records small {
  color: var(--muted);
  font-size: 11px;
  overflow-wrap: anywhere;
}

.sub-records small {
  grid-column: 1 / -1;
}

.sub-empty {
  padding: 10px;
  color: var(--muted);
  text-align: center;
  font-size: 12px;
}

.inline-link {
  color: var(--accent);
  text-decoration: none;
}

.danger-text {
  color: var(--danger);
}

.line-qty {
  flex: 0 0 auto;
  max-width: 42%;
  padding: 5px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  overflow-wrap: anywhere;
  text-align: right;
}

@media (min-width: 720px) {
  .app-shell {
    padding-inline: 18px;
  }

  .metric-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .content {
    max-width: 980px;
    margin: 0 auto;
  }

  .customer-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .order-list:not(.is-grouped) {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .customer-group-body {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .detail-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .module-metric-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (max-width: 430px) {
  .detail-money-grid,
  .detail-status-grid {
    grid-template-columns: 1fr;
  }

  .line-stat-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .record-group > summary,
  .row-record {
    gap: 7px;
  }
}
