:root {
  --bg: #0b1220;
  --card: #121c2f;
  --card2: #1a2744;
  --text: #e8eef8;
  --muted: #8b9bb4;
  --accent: #38bdf8;
  --ok: #34d399;
  --warn: #fbbf24;
  --danger: #f87171;
  --radius: 14px;
  --shadow: 0 8px 24px rgba(0,0,0,.35);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); min-height: 100%; }
html { overflow-x: hidden; }
body { overflow-x: hidden; }
a { color: var(--accent); text-decoration: none; }

.topbar {
  position: sticky; top: 0; z-index: 50;
  background: rgba(11,18,32,.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(255,255,255,.06);
}
.topbar-inner {
  max-width: 560px; margin: 0 auto; padding: 12px 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.brand { font-weight: 700; letter-spacing: .02em; color: var(--text); }
.who { font-size: 12px; color: var(--muted); }

.wrap {
  max-width: 560px; margin: 0 auto; padding: 16px 16px 132px;
}

.grid-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.grid-cards.grid-profit {
  grid-template-columns: 1fr;
}
@media (min-width: 400px) {
  .grid-cards.grid-profit {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}
@media (min-width: 420px) {
  .grid-cards { gap: 14px; }
}

.card {
  background: linear-gradient(145deg, var(--card), var(--card2));
  border-radius: var(--radius);
  padding: 14px 14px 12px;
  box-shadow: var(--shadow);
  border: 1px solid rgba(255,255,255,.06);
}
.card-tap:active { transform: scale(.98); transition: transform .08s; }
.card-label { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.card-value { font-size: 22px; font-weight: 700; letter-spacing: .02em; }
.card-sub { margin-top: 6px; font-size: 12px; color: var(--muted); }
.card-full { grid-column: 1 / -1; }

.row-cards {
  display: flex; flex-direction: column; gap: 12px;
}

.list-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px 16px;
  border: 1px solid rgba(255,255,255,.06);
  display: block; color: inherit;
}
.list-card + .list-card { margin-top: 0; }
.list-title { font-weight: 600; margin-bottom: 4px; }
.list-meta { font-size: 12px; color: var(--muted); }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 12px 18px; border-radius: 12px; border: none; cursor: pointer;
  font-size: 15px; font-weight: 600; color: #041018; background: var(--accent);
}
.btn-block { width: 100%; }
.btn-ghost {
  background: transparent; color: var(--accent);
  border: 1px solid rgba(56,189,248,.4);
}
.btn-danger { background: var(--danger); color: #1a0505; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 12px 14px; border-radius: 12px;
  border: 1px solid rgba(255,255,255,.1);
  background: rgba(0,0,0,.25); color: var(--text); font-size: 16px;
}
.field textarea { min-height: 80px; resize: vertical; }

/* 订单/采购「明细」多行：窄屏下须 minmax(0,…) + 子项 min-width:0，否则数量/单价框会撑破网格 */
.line-row {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(0, 0.85fr) minmax(0, 0.85fr);
  gap: 8px;
  margin-bottom: 10px;
  align-items: stretch;
}
.line-row > select,
.line-row > input {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  padding: 10px 10px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,.1);
  background: rgba(0,0,0,.25);
  color: var(--text);
  font-size: 16px;
  box-sizing: border-box;
}
.line-row > select {
  overflow: hidden;
  text-overflow: ellipsis;
}
@media (max-width: 360px) {
  .line-row {
    grid-template-columns: minmax(0, 1fr) minmax(0, 0.75fr) minmax(0, 0.75fr);
    gap: 6px;
  }
}

/* 新建订单：产品名称独占一行，成本/数量/单价第二行 */
.line-row.line-row--order {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}
.line-row.line-row--order > input.line-product-search {
  grid-column: 1 / -1;
  order: 1;
}
.line-row.line-row--order > input.line-cost-display {
  grid-column: 1 / 2;
  order: 2;
}
.line-row.line-row--order > input[name="quantity[]"] {
  grid-column: 2 / 3;
  order: 3;
}
.line-row.line-row--order > input[name="unit_price[]"] {
  grid-column: 3 / 4;
  order: 4;
}
.line-row.line-row-head {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 4px;
  align-items: end;
}
.line-row.line-row-head > span { padding: 0 2px 4px; }
.line-row.line-row-head > span:first-child { text-align: left; }
.line-row.line-row-head > span:not(:first-child) { text-align: center; }
.line-row.line-row-head.line-row--order {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}
.line-row.line-row-head.line-row--order > span:first-child {
  grid-column: 1 / -1;
  text-align: left;
}
.line-row > input.line-cost-display {
  text-align: center;
  color: var(--warn);
  font-size: 14px;
  font-weight: 600;
  cursor: default;
}
@media (max-width: 360px) {
  .line-row.line-row--order {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
  }
  .line-row.line-row--order > input.line-product-search {
    grid-column: 1 / -1;
    order: 1;
  }
  .line-row.line-row--order > input.line-cost-display {
    grid-column: 1 / 2;
    order: 2;
  }
  .line-row.line-row--order > input[name="quantity[]"] {
    grid-column: 2 / 3;
    order: 3;
  }
  .line-row.line-row--order > input[name="unit_price[]"] {
    grid-column: 3 / 4;
    order: 4;
  }
}

.flash {
  padding: 12px 14px; border-radius: 12px; margin-bottom: 14px; font-size: 14px;
}
.flash-ok { background: rgba(52,211,153,.15); color: var(--ok); border: 1px solid rgba(52,211,153,.3); }
.flash-err { background: rgba(248,113,113,.12); color: var(--danger); border: 1px solid rgba(248,113,113,.25); }

.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600;
}
.badge-ok { background: rgba(52,211,153,.2); color: var(--ok); }
.badge-warn { background: rgba(251,191,36,.2); color: var(--warn); }
.badge-muted { background: rgba(255,255,255,.08); color: var(--muted); }

/* 底部主导航：与顶栏（单条标题+用户）结构不同，五等分文字入口；勿与 .topbar 混用样式 */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  width: 100%;
  max-width: 100vw;
  box-sizing: border-box;
  background: linear-gradient(180deg, rgba(17,24,39,.97) 0%, rgba(8,12,22,.99) 100%);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid rgba(56,189,248,.18);
  box-shadow: 0 -6px 24px rgba(0,0,0,.35);
  padding-top: 10px;
  padding-left: max(6px, env(safe-area-inset-left, 0px));
  padding-right: max(6px, env(safe-area-inset-right, 0px));
  padding-bottom: 0;
  transform: translateZ(0);
}
.tabbar-inner {
  max-width: 560px; margin: 0 auto;
  display: flex; justify-content: stretch; align-items: stretch;
  align-content: stretch;
  min-height: 54px;
}
.tabbar .tab {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  text-decoration: none;
  padding: 12px 2px 14px;
  margin: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  -webkit-tap-highlight-color: transparent;
}
.tabbar .tab + .tab {
  border-left: 1px solid rgba(255,255,255,.07);
}
.tabbar .tab .tab-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: 0.02em;
  color: #a8b8d0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
.tabbar .tab:visited .tab-label { color: #a8b8d0; }
.tabbar .tab:hover .tab-label,
.tabbar .tab:focus .tab-label {
  color: var(--accent);
}
.safe-bottom {
  padding-bottom: max(16px, calc(10px + env(safe-area-inset-bottom, 0px)));
}

.section-title {
  font-size: 15px; font-weight: 700; margin: 20px 0 10px; color: var(--muted);
}
.toolbar { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }

/* 列表页：订单 / 产品 / 客户 搜索 */
.list-search-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  flex: 1 1 220px;
  min-width: 0;
}
.list-search-form--grow {
  flex: 1 1 260px;
}
.list-search-input,
.list-search-month {
  flex: 1 1 140px;
  min-width: 0;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(0, 0, 0, 0.22);
  color: var(--text);
  font-size: 15px;
}
.list-search-month {
  flex: 0 0 auto;
  width: auto;
  min-width: 9.5rem;
}

.list-pager-meta {
  font-size: 13px;
  color: var(--muted);
  align-self: center;
}

.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -4px;
  padding-bottom: 4px;
}
.table-scroll table.simple { min-width: 100%; }
@media (max-width: 480px) {
  .table-scroll .order-items-table { min-width: 34rem; }
}

table.simple { width: 100%; border-collapse: collapse; font-size: 14px; }
table.simple th, table.simple td { padding: 8px 6px; text-align: left; border-bottom: 1px solid rgba(255,255,255,.06); }
table.simple th { color: var(--muted); font-weight: 600; font-size: 12px; }

.empty { text-align: center; color: var(--muted); padding: 28px 12px; font-size: 14px; }

/* 业绩简报：当月日历式销售/毛利 */
.stats-cal-legend {
  font-size: 12px;
  color: var(--muted);
  margin: -6px 0 12px;
  line-height: 1.45;
}
.stats-calendar {
  padding: 12px 10px 14px;
  margin-bottom: 4px;
}
.stats-cal-weekdays {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 4px;
  margin-bottom: 8px;
  padding: 0 2px;
}
.stats-cal-weekdays span {
  text-align: center;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.02em;
}
.stats-cal-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 5px;
}
.stats-cal-cell {
  border-radius: 10px;
  min-height: 0;
}
.stats-cal-cell--empty {
  visibility: hidden;
  pointer-events: none;
}
.stats-cal-cell--day {
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid rgba(255, 255, 255, 0.07);
  padding: 5px 4px 6px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
}
.stats-cal-cell--zero {
  opacity: 0.72;
}
.stats-cal-cell--today {
  border-color: rgba(56, 189, 248, 0.55);
  box-shadow: 0 0 0 1px rgba(56, 189, 248, 0.2);
  background: rgba(56, 189, 248, 0.08);
}
.stats-cal-day {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
}
.stats-cal-metrics {
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1;
  justify-content: flex-end;
}
.stats-cal-line {
  display: flex;
  align-items: baseline;
  gap: 3px;
  font-size: 10px;
  line-height: 1.25;
  min-width: 0;
}
.stats-cal-k {
  flex-shrink: 0;
  color: var(--muted);
  font-weight: 600;
  width: 1em;
}
.stats-cal-v {
  min-width: 0;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  word-break: break-all;
}
.stats-cal-v--gp {
  color: var(--ok);
}
@media (min-width: 400px) {
  .stats-cal-cell--day {
    padding: 7px 5px 8px;
  }
  .stats-cal-line {
    font-size: 11px;
  }
  .stats-cal-day {
    font-size: 14px;
  }
}
