* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --line: #e6e8ec;
  --text: #1b1f24;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --green: #0f9d58;
  --orange: #e08b00;
  --red: #d93636;
  --radius: 10px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.55;
}

.hidden { display: none !important; }

/* 登录 */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #eef2ff, #f5f6f8 60%);
}
.login-card {
  width: 360px;
  background: var(--panel);
  padding: 36px 32px;
  border-radius: 14px;
  box-shadow: 0 8px 32px rgba(20, 30, 60, .1);
}
.login-card h1 { font-size: 22px; margin-bottom: 6px; }
.login-sub { color: var(--muted); font-size: 13px; margin-bottom: 24px; }
.login-card label { display: block; margin-bottom: 16px; font-size: 13px; color: var(--muted); }
.login-card input {
  width: 100%; margin-top: 6px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 8px; font-size: 14px;
}
.login-card input:focus { outline: 2px solid rgba(37, 99, 235, .25); border-color: var(--primary); }

/* 布局 */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 200px; flex-shrink: 0; background: #111827; color: #cbd5e1;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.brand { padding: 20px 18px; font-size: 16px; font-weight: 600; color: #fff; letter-spacing: .3px; }
.sidebar nav { flex: 1; padding: 8px; }
.sidebar nav a {
  display: block; padding: 10px 14px; color: #cbd5e1; text-decoration: none;
  border-radius: 8px; margin-bottom: 2px; font-size: 14px;
}
.sidebar nav a:hover { background: #1f2937; color: #fff; }
.sidebar nav a.active { background: var(--primary); color: #fff; }
.sidebar-foot { padding: 12px; border-top: 1px solid #1f2937; }
.who { font-size: 12px; color: #94a3b8; margin-bottom: 8px; }

.main { flex: 1; min-width: 0; padding: 20px 24px 60px; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; flex-wrap: wrap; margin-bottom: 20px;
}
.filters { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.filters select, .filters input {
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: #fff; font-size: 13px; color: var(--text);
}
.sep { color: var(--muted); font-size: 12px; }
.page-title { font-size: 20px; font-weight: 600; }

/* 卡片 */
.panel { background: var(--panel); border-radius: var(--radius); margin-bottom: 18px; border: 1px solid var(--line); }
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; padding: 14px 18px; border-bottom: 1px solid var(--line);
}
.panel-head h2 { font-size: 15px; font-weight: 600; }
.panel-tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.panel-tools input, .panel-tools select {
  padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 13px;
}

/* KPI */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px;
}
.kpi .label { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.kpi .value { font-size: 24px; font-weight: 600; letter-spacing: -.3px; }
.kpi .sub { font-size: 12px; color: var(--muted); margin-top: 4px; }
.kpi.green .value { color: var(--green); }
.kpi.orange .value { color: var(--orange); }
.kpi.blue .value { color: var(--primary); }
.kpi.red .value { color: var(--red); }

/* 经营总额：线下 / 线上 / 工厂三卡 */
.period-cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; padding: 14px 18px 18px; }
.period-card { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.period-card-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
  padding: 10px 12px; background: #fafbfc; border-bottom: 1px solid var(--line);
}
.period-card-head h3 { font-size: 13px; font-weight: 600; }
.period-card-head span { font-size: 11px; color: var(--muted); }
.period-card table.mini th, .period-card table.mini td { padding: 8px 12px; }
.period-card tbody tr:last-child td { border-bottom: none; }
@media (max-width: 900px) { .period-cards { grid-template-columns: 1fr; } }

/* 表格 */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { background: #fafbfc; color: var(--muted); font-weight: 500; font-size: 12px; }
tbody tr:hover { background: #fafbfc; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { text-align: center; color: var(--muted); padding: 28px; }

/* 状态标记 */
.tag { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 12px; font-weight: 500; }
.tag.ok { background: #e7f7ee; color: var(--green); }
.tag.wait { background: #fdf3e3; color: var(--orange); }
.tag.warn { background: #fdeaea; color: var(--red); }
.tag.none { background: #f1f2f4; color: var(--muted); }

/* 按钮 */
.btn {
  padding: 8px 14px; border: 1px solid var(--line); background: #fff; border-radius: 8px;
  cursor: pointer; font-size: 13px; color: var(--text); font-family: inherit;
}
.btn:hover { background: #f7f8fa; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: transparent; border-color: #374151; color: #cbd5e1; }
.btn-ghost:hover { background: #1f2937; }
.btn-block { width: 100%; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* 表单 */
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px 18px; padding: 18px; }
.form-grid label { font-size: 13px; color: var(--muted); display: block; }
.form-grid label input, .form-grid label select {
  width: 100%; margin-top: 5px; padding: 9px 11px;
  border: 1px solid var(--line); border-radius: 8px; font-size: 14px; font-family: inherit;
}
.span-2 { grid-column: span 2; }
.form-actions { display: flex; align-items: center; gap: 12px; padding-top: 4px; }

.items-block { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.items-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.items-head h3 { font-size: 13px; font-weight: 600; color: var(--muted); }
#tbl-items input {
  width: 100%; padding: 7px 9px; border: 1px solid var(--line);
  border-radius: 6px; font-size: 13px; font-family: inherit;
}
#tbl-items td { padding: 5px 6px; }
.item-del { color: var(--red); cursor: pointer; background: none; border: none; font-size: 13px; }

.cost-summary {
  display: flex; align-items: center; gap: 20px; flex-wrap: wrap;
  margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--line); font-size: 13px;
}
.cost-summary b { font-size: 15px; color: var(--primary); }
label.inline { display: flex; align-items: center; gap: 8px; color: var(--muted); }
label.inline input { width: 160px; padding: 7px 9px; border: 1px solid var(--line); border-radius: 6px; }
.hint { font-size: 12px; color: var(--muted); }
.err { color: var(--red); font-size: 13px; margin-top: 10px; min-height: 18px; }

.inline-form { display: flex; gap: 10px; flex-wrap: wrap; padding: 16px 18px; }
.inline-form input, .inline-form select {
  padding: 8px 11px; border: 1px solid var(--line); border-radius: 8px; font-size: 13px; font-family: inherit;
}

/* 导入 */
.import-box { padding: 18px; }
.import-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 14px 0; }
.import-row select, .import-row input[type=file] {
  padding: 8px 11px; border: 1px solid var(--line); border-radius: 8px; font-size: 13px;
}
.import-result { font-size: 13px; }
.import-result .ok-line { color: var(--green); }
.import-result .warn-line { color: var(--orange); }

/* 分页 */
.pager { display: flex; align-items: center; justify-content: center; gap: 14px; padding: 14px; font-size: 13px; color: var(--muted); }

/* 提示 */
.toast {
  position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%);
  background: #1f2937; color: #fff; padding: 11px 20px; border-radius: 8px;
  font-size: 13px; box-shadow: 0 6px 24px rgba(0,0,0,.2); z-index: 999;
}
.toast.error { background: var(--red); }

/* 弹窗 */
.modal-mask {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .45);
  display: flex; align-items: center; justify-content: center; z-index: 900; padding: 20px;
}
.modal {
  background: #fff; border-radius: 12px; width: min(900px, 100%);
  max-height: 88vh; overflow: auto;
}
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-head h2 { font-size: 15px; }
.modal-body { padding: 18px 20px; }
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 18px; }
.kv div { font-size: 13px; }
.kv .k { color: var(--muted); font-size: 12px; }
.kv .v { font-weight: 500; }

/* 订单明细弹窗：回款/支出明细表 */
.sec-title { font-size: 13px; color: var(--muted); margin-bottom: 8px; font-weight: 600; }
.muted { color: var(--muted); }
table .sum-row td { background: #fafbfc; font-weight: 600; }
/* 订单详情里合并后的流水行：可点击展开，子行弱化显示 */
table tr.lg-main:hover td { background: #f7f9fc; }
table tr.lg-sub td { background: #fafbfc; color: var(--muted); font-size: 12px; padding-left: 18px; }
.lg-caret { color: var(--muted); font-size: 11px; }
.tag.ledger { background: #e8f0fe; color: #1a56c4; }
.tag.sheet { background: #eef7e8; color: #3d7a1f; }
.tag.purchase { background: #f1f2f4; color: var(--muted); }
.expense-mini { font-size: 12px; color: var(--muted); line-height: 1.5; }
td.detail-cell { max-width: 320px; font-size: 12px; }

/* ---------- 金山文档同步 ---------- */
.wps-preview { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 14px; }
.wps-preview-head { font-size: 13px; color: var(--muted); margin-bottom: 12px; }
.wps-preview-head b { color: var(--text); }
.wps-preview-head .ok { color: var(--green, #3d7a1f); }
.wps-preview-head .warn { color: var(--orange); }
.warn-box { background: #fff8ec; border: 1px solid #f6e0b8; border-radius: 6px;
  padding: 10px 14px; font-size: 12px; color: #8a5a10; margin-bottom: 14px; }
.warn-box ul { margin: 6px 0 0; padding-left: 18px; line-height: 1.7; }
.wps-preview-cols { display: grid; grid-template-columns: minmax(180px, 1fr) 2fr; gap: 16px; margin-bottom: 16px; }
.wps-preview h4 { font-size: 12px; color: var(--muted); margin: 12px 0 6px; font-weight: 600; }
table.mini { font-size: 12px; }
table.mini th, table.mini td { padding: 5px 8px; }
.row-actions { white-space: nowrap; }
.row-actions .btn { margin-right: 4px; }
.row-actions .btn:last-child { margin-right: 0; }
.btn-danger { color: var(--red); border-color: #f3c9c9; }
.btn-danger:hover { background: #fdeaea; }

/* 浏览器桥接 */
.bridge-sheets { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.bridge-sheet {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  padding: 9px 14px; border: 1px solid var(--line); background: #fff;
  border-radius: 8px; cursor: pointer; font-family: inherit; text-align: left;
}
.bridge-sheet:hover { border-color: var(--primary); background: #f5f8ff; }
.bridge-sheet .bs-name { font-size: 13px; color: var(--text); }
.bridge-sheet .bs-dim { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.bridge-sheet.empty-sheet { opacity: .5; }

@media (max-width: 860px) {
  .wps-preview-cols { grid-template-columns: 1fr; }
}

@media (max-width: 860px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; flex-wrap: wrap; align-items: center; }
  .sidebar nav { display: flex; flex-wrap: nowrap; overflow-x: auto; flex: 1 0 100%; min-width: 0; }
  .sidebar nav a { white-space: nowrap; flex: 0 0 auto; }
  .sidebar-foot { display: flex; gap: 10px; align-items: center; border: none; width: 100%; }
  .form-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: span 1; }
}

/* ---------- 手机端 ---------- */
.table-wrap { -webkit-overflow-scrolling: touch; }

@media (max-width: 860px) {
  .main { padding: 14px 12px 48px; }
  .topbar { gap: 10px; margin-bottom: 14px; }
  .page-title { font-size: 18px; }
  .filters { width: 100%; gap: 6px; }
  .filters select, .filters input { flex: 1 1 120px; min-width: 0; }
  .filters .sep { display: none; }

  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi { padding: 12px 13px; }
  .kpi .value { font-size: 19px; }

  .panel { margin-bottom: 12px; border-radius: 8px; }
  .panel-head { padding: 12px 14px; }
  .panel-tools { width: 100%; }
  .panel-tools .btn { flex: 1 1 auto; }
  .import-box { padding: 14px; }
  .import-row { flex-direction: column; align-items: stretch; }
  .import-row select, .import-row input[type=file] { width: 100%; }
  .form-grid { padding: 14px; gap: 12px; }
  .form-actions { flex-wrap: wrap; }
  .form-actions .btn { flex: 1 1 auto; }
  .form-grid input[type=file] { padding: 7px; }

  th, td { padding: 9px 10px; }
  .row-actions { white-space: normal; min-width: 128px; }
  .row-actions .btn { margin-bottom: 4px; }
  .wps-preview-cols { grid-template-columns: 1fr; }

  .modal-mask { padding: 8px; align-items: flex-end; }
  .modal { max-height: 92vh; border-radius: 12px 12px 0 0; width: 100%; }
  .modal-body { padding: 14px; }
  .toast { left: 12px; right: 12px; transform: none; bottom: 14px; text-align: center; }

  .sidebar { padding-bottom: 2px; }
  .brand { padding: 14px; }
  .sidebar nav { padding: 0 8px 8px; }
  .sidebar nav a { padding: 8px 12px; font-size: 13px; }
  .sidebar-foot { padding: 8px 12px 12px; }
  .who { margin-bottom: 0; }
  .login-wrap { padding: 16px; }
  .login-card { width: 100%; max-width: 360px; padding: 28px 22px; }
}


/* 网格子项默认 min-width:auto，宽表格会把整列撑出屏幕；显式压回 0 交给 table-wrap 横向滚动 */
.form-grid > * { min-width: 0; }
.items-block { min-width: 0; }
.table-wrap { max-width: 100%; }

@media (max-width: 860px) {
  .sidebar-foot { flex-wrap: wrap; gap: 8px; }
  .sidebar-foot .who { flex: 1 1 auto; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .sidebar-foot .btn { flex: 0 0 auto; padding: 6px 10px; font-size: 12px; }
  .sidebar-foot .btn-block { width: auto; }
}
