:root {
  --bg: #f5f6f7;
  --surface: #fff;
  --border: #e5e6eb;
  --border-light: #f0f1f3;
  --text: #1f2329;
  --text-muted: #8f959e;
  --primary: #3370ff;
  --green: #078372;
  --red: #e34d59;
  --feishu-radius: 8px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "PingFang SC", "Microsoft YaHei", -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  line-height: 1.4;
}

.header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 16px;
}

.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

h1 { font-size: 16px; font-weight: 600; }
h2 { font-size: 13px; font-weight: 600; color: var(--text); }
.as-of { color: var(--text-muted); font-size: 12px; }

.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 12px 16px 24px;
}

.cards {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

@media (max-width: 900px) { .cards { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 480px) { .cards { grid-template-columns: repeat(2, 1fr); } }

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 12px;
}

.stat-card .label { font-size: 11px; color: var(--text-muted); }
.stat-card .value { font-size: 18px; font-weight: 700; color: var(--green); }
.stat-card .sub { font-size: 11px; color: var(--text-muted); }

/* 新建订单 */
.quick-bar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  margin-bottom: 12px;
}

.quick-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
  font-size: 12px;
  flex-wrap: wrap;
}

.quick-label { font-weight: 600; }

.hidden { display: none !important; }

.rate-tag {
  background: #fff7e6;
  color: #d48806;
  border: 1px solid #ffd591;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
}

.rate-tag.zero {
  background: #f6ffed;
  color: var(--green);
  border-color: #b7eb8f;
}

.profit-inline {
  font-weight: 700;
  color: var(--green);
  margin-left: auto;
}

.quick-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.q-input {
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 6px;
  height: 28px;
  font-size: 12px;
  background: #fff;
  font-family: inherit;
}

.q-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 2px rgba(51, 112, 255, 0.12); }

.q-date { width: 118px; }
.q-status { width: 72px; }
.q-name { width: 56px; }
.q-item { width: 72px; }
.q-custom { width: 80px; }
.q-rate { width: 48px; }
.q-phone { width: 96px; }
.q-num { width: 64px; }
.q-platform { width: 96px; }
.q-addr { flex: 1; min-width: 120px; }

.addr-hint {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
}

/* 解析订单 */
.parse-bar {
  margin-top: 10px;
  border-top: 1px solid var(--border-light);
  padding-top: 10px;
}

.parse-bar-head {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}

.parse-label {
  font-weight: 600;
  font-size: 12px;
}

.parse-hint {
  font-size: 11px;
  color: var(--text-muted);
  flex: 1;
  min-width: 120px;
}

.parse-textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 12px;
  font-family: inherit;
  line-height: 1.5;
  resize: vertical;
  min-height: 72px;
  background: #fafbfc;
}

.parse-textarea:focus {
  outline: none;
  border-color: var(--primary);
  background: #fff;
  box-shadow: 0 0 0 2px rgba(51, 112, 255, 0.12);
}

.btn {
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #fff;
  padding: 4px 10px;
  height: 28px;
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
}

.btn-xs { height: 28px; line-height: 1; padding: 0 10px; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary-soft {
  background: #e8f3ff;
  border-color: #b8d4ff;
  color: var(--primary);
}
.btn-primary-soft:hover { background: #d6e8ff; }
.btn-danger { color: var(--red); border-color: #f5c2c7; background: #fff; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  margin-bottom: 12px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
  gap: 8px;
  flex-wrap: wrap;
}

.collapse-toggle {
  display: flex;
  align-items: center;
  gap: 4px;
  background: none;
  border: none;
  cursor: pointer;
  font: inherit;
  padding: 0;
}

.collapse-icon { font-size: 10px; color: var(--text-muted); }
.collapsible-card.is-open .collapse-icon { transform: rotate(90deg); }
.collapsible-card.is-open .collapsible-body { display: block; margin-top: 6px; }
.collapsible-body[hidden] { display: none; }

.badge { font-size: 12px; color: var(--green); font-weight: 600; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 768px) { .grid-2 { grid-template-columns: 1fr; } }

.select-sm, .input-sm {
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 8px;
  height: 30px;
  font-size: 12px;
  background: #fff;
  font-family: inherit;
}

.select-sm:focus, .input-sm:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(51, 112, 255, 0.12);
}

.data-table.compact {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.data-table.compact th,
.data-table.compact td {
  border: 1px solid var(--border);
  padding: 6px 8px;
  text-align: left;
}

.data-table.compact th {
  background: #f7f8fa;
  color: var(--text-muted);
  font-weight: 500;
}

.profit-pos { color: var(--green); font-weight: 600; }
.total-row td { font-weight: 600; background: #fafafa; }

#daily-chart { max-height: 200px; }

.insight {
  padding: 6px 8px;
  border-left: 3px solid var(--primary);
  background: #fafafa;
  margin-bottom: 6px;
  font-size: 12px;
  border-radius: 0 4px 4px 0;
}

.insight .message { color: var(--text-muted); font-size: 11px; }

.toast {
  position: fixed;
  bottom: 16px;
  right: 16px;
  background: #333;
  color: #fff;
  padding: 8px 14px;
  font-size: 12px;
  z-index: 200;
  border-radius: 6px;
}

.toast.hidden { opacity: 0; pointer-events: none; transition: opacity 0.3s; }

/* ===== 订单列表 — 飞书风格 ===== */
.feishu-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--feishu-radius);
  padding: 12px 14px;
  margin-bottom: 12px;
}

.feishu-card-header {
  margin-bottom: 10px;
}

.filter-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  background: #f7f8fa;
  border: 1px solid var(--border-light);
  border-radius: 6px;
  padding: 8px 10px;
  margin-bottom: 10px;
}

.search-input { width: 200px; min-width: 140px; }
.date-filter { width: 118px; }
.filter-sep { color: var(--text-muted); font-size: 12px; }

.table-scroll {
  overflow: auto;
  max-height: min(72vh, 720px);
  border: 1px solid var(--border);
  border-radius: var(--feishu-radius);
  background: #fff;
}

.feishu-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 12px;
  table-layout: fixed;
  min-width: 1080px;
}

.feishu-table th,
.feishu-table td {
  border-bottom: 1px solid var(--border-light);
  border-right: 1px solid var(--border-light);
  padding: 0;
  height: 40px;
  vertical-align: middle;
}

.feishu-table th:last-child,
.feishu-table td:last-child { border-right: none; }

.feishu-table tbody tr:last-child td { border-bottom: none; }

.feishu-table thead {
  position: sticky;
  top: 0;
  z-index: 5;
}

.feishu-table thead th {
  background: #f2f3f5;
  color: #646a73;
  font-weight: 600;
  font-size: 12px;
  padding: 0 8px;
  white-space: nowrap;
  height: 38px;
  line-height: 38px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 0 var(--border-light);
}

.feishu-table thead th.th-act,
.feishu-table thead th.th-date,
.feishu-table thead th.th-status,
.feishu-table thead th.th-platform {
  text-align: center;
}

.feishu-table thead th.th-rate {
  text-align: right;
  padding-right: 8px;
  border-left: 2px solid #e5e6eb;
}

.feishu-table thead th.th-profit-h {
  color: var(--green);
  text-align: right;
  padding-right: 10px;
}

.feishu-table thead th.th-money {
  text-align: right;
  padding-right: 10px;
}

.feishu-table td:nth-child(8) {
  border-left: 2px solid #f0f1f3;
}

/* 列宽与对齐 */
.feishu-table .th-act,
.feishu-table td.col-act { width: 56px; min-width: 56px; text-align: center; }

.feishu-table .th-date,
.feishu-table td:nth-child(2) { width: 92px; min-width: 92px; }

.feishu-table .th-cust,
.feishu-table td:nth-child(3) { width: 52px; min-width: 52px; }

.feishu-table .th-phone,
.feishu-table td:nth-child(4) { width: 100px; min-width: 100px; }

.feishu-table .th-item,
.feishu-table td:nth-child(5) { width: 88px; min-width: 88px; }

.feishu-table .th-status,
.feishu-table td:nth-child(6) { width: 76px; min-width: 76px; }

.feishu-table .th-platform,
.feishu-table td:nth-child(7) { width: 80px; min-width: 80px; }

.feishu-table .th-rate,
.feishu-table td:nth-child(8) { width: 44px; min-width: 44px; }

.feishu-table .th-money,
.feishu-table td:nth-child(9),
.feishu-table td:nth-child(10) { width: 68px; min-width: 68px; }

.feishu-table th.th-profit-h,
.feishu-table td.profit-cell { width: 68px; min-width: 68px; }

.feishu-table .th-staff,
.feishu-table td:nth-child(12) { width: 48px; min-width: 48px; }

.feishu-table .th-addr,
.feishu-table td:nth-child(13) { width: 120px; min-width: 120px; }

.feishu-table .th-area,
.feishu-table td:nth-child(14),
.feishu-table td:nth-child(15) { width: 72px; min-width: 72px; }

.feishu-table tbody tr { transition: background 0.12s; }
.feishu-table tbody tr:hover { background: #f5f8ff; }
.feishu-table tbody tr.row-highlight { background: #e8f3ff; }
.feishu-table tbody tr.row-saving { background: #fffbe6; }
.feishu-table tbody tr.row-saved { background: #f0faf7; }

/* 操作列固定左侧 */
.col-sticky {
  position: sticky;
  left: 0;
  z-index: 3;
  background: inherit;
  box-shadow: 2px 0 6px rgba(0, 0, 0, 0.05);
}

.feishu-table thead .col-sticky {
  background: #f2f3f5;
  z-index: 6;
}

.feishu-table tbody tr:hover .col-sticky { background: #f5f8ff; }
.feishu-table tbody tr.row-highlight .col-sticky { background: #e8f3ff; }

.col-act {
  text-align: center;
  padding: 0 4px !important;
}

/* 飞书标签 */
.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  line-height: 18px;
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: middle;
}

.tag-status-done {
  background: #fff3e0;
  color: #ed6a0c;
  border: 1px solid #ffd591;
}

.tag-status-pending {
  background: #e8f3ff;
  color: #3370ff;
  border: 1px solid #b8d4ff;
}

.tag-pink { background: #fff0f6; color: #c41d7f; border: 1px solid #ffadd2; }
.tag-orange { background: #fff7e6; color: #d46b08; border: 1px solid #ffd591; }
.tag-blue { background: #e8f3ff; color: #245bdb; border: 1px solid #b8d4ff; }
.tag-purple { background: #f3f0ff; color: #6425c0; border: 1px solid #d3adf7; }
.tag-cyan { background: #e6fffb; color: #08979c; border: 1px solid #87e8de; }
.tag-green { background: #f6ffed; color: #389e0d; border: 1px solid #b7eb8f; }
.tag-gray { background: #f5f5f5; color: #595959; border: 1px solid #d9d9d9; }
.tag-default { background: #f5f5f5; color: #595959; border: 1px solid #e8e8e8; }

/* 点击编辑单元格 */
.cell {
  position: relative;
  height: 100%;
  min-height: 38px;
  cursor: pointer;
  display: flex;
  align-items: center;
}

.cell-display {
  display: block;
  padding: 0 8px;
  line-height: 38px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 12px;
  width: 100%;
}

.cell-display.hidden { display: none; }

.cell-display .tag { line-height: 16px; margin-top: 1px; }

.cell-long .cell-display {
  padding-right: 28px;
  cursor: pointer;
}

.cell-long::after {
  content: "全文";
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 10px;
  color: #3370ff;
  background: #e8f3ff;
  padding: 1px 5px;
  border-radius: 3px;
  line-height: 16px;
  pointer-events: none;
}

.cell-editor {
  width: 100%;
  height: 36px;
  border: none;
  padding: 0 8px;
  font-size: 12px;
  font-family: inherit;
  background: #fff;
  outline: 2px solid var(--primary);
  outline-offset: -2px;
  border-radius: 2px;
}

.cell-editor.hidden { display: none; }

.cell-num .cell-display,
.cell-num .cell-editor { text-align: right; }

.cell-long .cell-display { color: var(--text); }

.cell.is-editing { z-index: 2; }

.platform-custom-wrap {
  padding: 2px 4px 4px;
}

.platform-custom-wrap.hidden { display: none; }

.platform-custom-inp {
  width: 100%;
  height: 24px;
  border: 1px solid var(--primary);
  border-radius: 4px;
  font-size: 11px;
  padding: 0 6px;
}

.cell-readonly {
  padding: 0 8px;
  color: var(--text-muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 40px;
}

.profit-cell {
  padding: 0 8px !important;
  text-align: right;
  font-weight: 600;
  line-height: 40px;
  font-size: 12px;
  color: var(--green);
}

.del-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 12px;
  padding: 4px 6px;
  border-radius: 4px;
  line-height: 1;
  white-space: nowrap;
}

.del-btn:hover {
  color: var(--red);
  background: #fff1f0;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 10px;
  font-size: 12px;
  color: var(--text-muted);
}

.page-jump { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; }
.page-input { width: 48px; text-align: center; padding: 2px 4px; }

@media (max-width: 768px) {
  .container { padding: 8px 10px 20px; }
  .header { padding: 8px 10px; }
  h1 { font-size: 15px; }
  .quick-row { gap: 4px; }
  .q-addr { min-width: 100%; }
  .feishu-card { padding: 8px; }
  .feishu-table { font-size: 11px; }
  .cell-display, .cell-editor { font-size: 11px; }
  .search-input { width: 100%; }
  .filter-bar { gap: 6px; }
}

/* 单元格放大 */
.cell-popover {
  position: fixed;
  inset: 0;
  z-index: 150;
  background: rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.cell-popover.hidden { display: none; }

.cell-popover-inner {
  width: min(640px, 94vw);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}

.cell-popover-head,
#cell-popover-body,
.cell-popover-foot {
  width: 100%;
  background: #fff;
}

.cell-popover-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-bottom: none;
  font-weight: 600;
}

.cell-popover-head button {
  border: none;
  background: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--text-muted);
  line-height: 1;
}

#cell-popover-body {
  display: block;
  border: 1px solid var(--border);
  border-top: none;
  border-bottom: none;
  padding: 12px;
  font-size: 14px;
  line-height: 1.6;
  font-family: inherit;
  resize: vertical;
  min-height: 100px;
  max-height: 50vh;
  outline: none;
  word-break: break-all;
}

.cell-popover-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 8px 8px;
}

.cell-popover-hint {
  font-size: 11px;
  color: var(--text-muted);
}

.cell-popover-actions {
  display: flex;
  gap: 6px;
}
