:root {
  --bg: #f3f5f8;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --brand: #0f5ea8;
  --brand-dark: #0b477e;
  --danger: #c62828;
  --danger-bg: #fdecec;
  --ok: #147a3d;
  --ok-bg: #e8f5ec;
  --warn: #a15c00;
  --warn-bg: #fff4df;
  --blue-bg: #e8f1fb;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.08);
  --radius: 8px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

h1, h2, h3 { margin: 0; font-weight: 700; }

button, input, select, textarea {
  font-family: inherit;
  font-size: 14px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 14px 24px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 40px; height: 40px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--brand); color: #fff;
  border-radius: 10px; font-size: 22px; font-weight: 700;
}
.brand h1 { font-size: 19px; letter-spacing: 0.3px; }
.brand .sub { color: var(--muted); font-size: 12px; }

.top-right { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.env-badge {
  display: inline-block; padding: 4px 10px; border-radius: 999px;
  background: var(--blue-bg); color: var(--brand); font-weight: 700; font-size: 12px;
}
.env-badge.prod { background: var(--danger-bg); color: var(--danger); }
.balance-box { display: flex; align-items: baseline; gap: 8px; }
.balance-label { color: var(--muted); font-size: 12px; }
#balanceValue { font-size: 22px; font-variant-numeric: tabular-nums; }
#balanceValue.low { color: var(--danger); }
.link-btn {
  border: 0; background: none; color: var(--brand);
  cursor: pointer; padding: 2px 4px; font-size: 12px; text-decoration: underline;
}
.link-btn:disabled { color: var(--muted); cursor: wait; }

.low-balance-bar {
  margin: 12px 24px 0;
  padding: 10px 14px;
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid #f3b9b9;
  border-radius: var(--radius);
  font-weight: 600;
}
.attention-banner {
  margin: 12px 24px 0;
  padding: 12px 14px;
  background: #fff0f0;
  color: #9b1c1c;
  border: 1px solid #f0b4b4;
  border-left: 5px solid var(--danger);
  border-radius: var(--radius);
  font-weight: 600;
}
#ordersSection .attention-banner {
  margin: 0 0 12px;
  line-height: 1.65;
}
.policy-banner {
  margin: 12px 24px 0;
  padding: 12px 14px;
  background: #fff0f0;
  color: #9b1c1c;
  border: 1px solid #f0b4b4;
  border-left: 5px solid var(--danger);
  border-radius: var(--radius);
  max-height: 210px;
  overflow-y: auto;
}
.policy-banner-title { font-weight: 700; line-height: 1.65; }
.policy-banner ul { margin: 8px 0 0; padding-left: 20px; }
.policy-banner li { margin: 5px 0; font-weight: 500; line-height: 1.6; }
.policy-banner-error { color: var(--danger); font-size: 12px; word-break: break-all; }

main {
  max-width: 1360px;
  margin: 0 auto;
  padding: 16px 24px 32px;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}

.section-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 14px; flex-wrap: wrap;
}
.section-head h2 { font-size: 17px; }
.section-tip { color: var(--muted); font-size: 12px; }
.orders-tools { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}
.field { display: flex; flex-direction: column; gap: 5px; }
.field > span { color: var(--muted); font-size: 12px; font-weight: 600; }
.field input, .field select {
  height: 36px; padding: 0 10px;
  border: 1px solid #cfd6e0; border-radius: 6px;
  background: #fff; color: var(--text); outline: none;
}
.field input:focus, .field select:focus, textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(15, 94, 168, 0.12);
}
.field-days .days-text {
  height: 36px; display: flex; align-items: center; padding: 0 10px;
  background: #f8fafc; border: 1px dashed #cfd6e0; border-radius: 6px;
  color: var(--brand); font-weight: 700;
}

.ocr-block { margin-top: 14px; }
.ocr-zone {
  display: flex; align-items: center; gap: 12px;
  padding: 13px 14px;
  border: 2px dashed #b9c6d8; border-radius: var(--radius);
  background: #f8fafc; cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
}
.ocr-zone:hover, .ocr-zone:focus-visible, .ocr-zone.dragover {
  border-color: var(--brand); background: #eef6ff; outline: none;
}
.ocr-zone-mark {
  width: 36px; height: 36px; flex: 0 0 auto;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 8px; background: var(--blue-bg); color: var(--brand);
  font-weight: 700; font-size: 15px;
}
.ocr-zone-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }
.ocr-zone-text strong { font-size: 14px; }
.ocr-zone-text span { color: var(--muted); font-size: 12px; }
.ocr-zone .btn { flex: 0 0 auto; }
.ocr-thumbs {
  display: flex; flex-wrap: wrap; gap: 10px;
  margin-top: 10px;
}
.ocr-thumb {
  margin: 0; width: 168px;
  border: 1px solid var(--line); border-radius: 7px;
  background: #fff; overflow: hidden;
}
.ocr-thumb img {
  display: block; width: 100%; height: 104px; object-fit: cover; background: #eef1f5;
}
.ocr-thumb figcaption {
  padding: 5px 7px; font-size: 11px; color: var(--muted);
  white-space: normal; word-break: break-all; line-height: 1.4;
}
.ocr-thumb .thumb-state { display: block; font-weight: 700; color: var(--brand); }
.ocr-thumb.done .thumb-state { color: var(--ok); }
.ocr-thumb.error .thumb-state { color: var(--danger); }
.ocr-status { margin-top: 8px; font-size: 12px; color: var(--ok); font-weight: 600; }
.ocr-status[hidden] { display: none; }
.ocr-error {
  margin-top: 8px; padding: 9px 11px;
  background: var(--danger-bg); border: 1px solid #f0b4b4; border-radius: 6px;
  color: var(--danger); font-size: 13px; font-weight: 600; white-space: pre-wrap;
}
.ocr-error[hidden] { display: none; }

.roster-block { margin-top: 14px; }
.roster-head { display: flex; flex-direction: column; gap: 4px; margin-bottom: 7px; }
.roster-head label { font-weight: 700; }
.hint { color: var(--muted); font-size: 12px; }
textarea {
  width: 100%; min-height: 150px; resize: vertical;
  padding: 10px 12px; border: 1px solid #cfd6e0; border-radius: 6px;
  line-height: 1.7; outline: none; background: #fff;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 13px;
}
.parse-summary { margin-top: 6px; font-size: 12px; color: var(--muted); min-height: 18px; }
.parse-summary .err { color: var(--danger); font-weight: 600; }
.parse-summary .good { color: var(--ok); font-weight: 600; }

.table-wrap { width: 100%; overflow-x: auto; }
.preview-wrap { margin-top: 10px; max-height: 330px; overflow-y: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td {
  padding: 8px 9px; text-align: left; vertical-align: top;
  border-bottom: 1px solid var(--line); white-space: nowrap;
}
th {
  position: sticky; top: 0; z-index: 1;
  background: #f8fafc; color: #475467;
  font-size: 12px; font-weight: 700;
}
tbody tr:hover { background: #fbfcfe; }
td.wrap { white-space: normal; min-width: 220px; }
.empty-row td { text-align: center; color: var(--muted); padding: 24px; }
.row-error td { background: #fff8f8; }
.row-error .row-error-text,
.row-error-text { color: var(--danger); font-size: 12px; white-space: normal; max-width: 280px; }
.mono { font-family: "SFMono-Regular", Consolas, Menlo, monospace; font-size: 12px; }
.money { font-variant-numeric: tabular-nums; }
.strong { font-weight: 700; }

/* 名单预览：行内可编辑；机器识别的行浅黄底并标注 */
.preview-table td { vertical-align: middle; }
.preview-table th:nth-child(1) { width: 46px; }
.preview-table th:nth-child(4),
.preview-table th:nth-child(6) { width: 58px; }
.preview-table th:nth-child(8) { width: 76px; }
.preview-table th:nth-child(9) { width: 180px; }
.cell-input {
  width: 100%; min-width: 70px; height: 28px;
  padding: 2px 5px; border: 1px solid transparent; border-radius: 4px;
  background: transparent; color: var(--text); font-size: 13px; outline: none;
}
.cell-input:hover { border-color: #cfd6e0; background: #fff; }
.cell-input:focus {
  border-color: var(--brand); background: #fff;
  box-shadow: 0 0 0 2px rgba(15, 94, 168, 0.12);
}
.cell-input.mono { font-size: 12px; }
.cell-input.card-input { min-width: 158px; }
.cell-input.name-input { min-width: 84px; }
.cell-input.birth-input { min-width: 108px; }
.cell-input.mobile-input { min-width: 104px; }
.row-machine td { background: #fffbe6; }
.row-machine:hover td { background: #fff6cf; }
.row-machine.row-error td { background: #fffbe6; }
.machine-note { color: var(--warn); font-size: 11px; line-height: 1.3; margin-top: 1px; }
.preview-table td.cell-valid { white-space: normal; min-width: 160px; }
.preview-table td.cell-valid .row-error-text { max-width: 180px; }

/* 订单列表：团号/保单号折行，人数与保费按内容收窄，状态与操作粘在右侧 */
.orders-wrap { overflow-x: auto; }
.orders-table { width: 100%; min-width: 0; }
.orders-table th.col-time { width: 160px; }
.orders-table th.col-operator { width: 64px; }
.orders-table th.col-group { width: 150px; }
.orders-table th.col-persons,
.orders-table th.col-amount { width: 1%; }
.orders-table th.col-order { width: 168px; }
.orders-table th.col-status { width: 200px; }
.orders-table th.col-actions { width: 200px; }
.orders-table td.col-group {
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.orders-table td.col-policy {
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-all;
}
.orders-table td.col-order { white-space: normal; word-break: break-all; }
.orders-table td.col-persons,
.orders-table td.col-amount { white-space: nowrap; }
.orders-table td.col-status,
.orders-table td.col-actions {
  position: sticky;
  z-index: 2;
  background: #fff;
}
.orders-table th.col-status,
.orders-table th.col-actions {
  position: sticky;
  z-index: 4;
  background: #f8fafc;
}
.orders-table td.col-status,
.orders-table th.col-status {
  right: 200px;
  box-shadow: -10px 0 12px -10px rgba(16, 24, 40, 0.28);
}
.orders-table td.col-actions,
.orders-table th.col-actions { right: 0; }
.orders-table tbody tr:hover td.col-status,
.orders-table tbody tr:hover td.col-actions { background: #fbfcfe; }
.orders-table td.col-status { text-align: right; }
.orders-table td.col-actions { text-align: right; }
.orders-table th.col-status,
.orders-table th.col-actions { text-align: right; }
.order-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  gap: 4px 6px;
  min-width: 182px;
}
.order-actions .btn-link { padding: 0 6px; }
.unpaid-note {
  display: inline-block;
  margin-left: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}

.actions { display: flex; align-items: center; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.action-hint { color: var(--muted); font-size: 12px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 36px; padding: 0 16px;
  border: 1px solid #cfd6e0; border-radius: 6px;
  background: #fff; color: var(--text); cursor: pointer; font-weight: 600;
  transition: background 0.12s, border-color 0.12s;
}
.btn:hover:not(:disabled) { background: #f5f7fa; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--brand-dark); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #a51f1f; }
.btn-small { min-height: 30px; padding: 0 10px; font-size: 12px; }
.btn-link {
  min-height: 28px; padding: 0 8px; border: 1px solid transparent;
  background: transparent; color: var(--brand); text-decoration: underline;
  font-size: 12px;
}
.btn-link:hover:not(:disabled) { background: var(--blue-bg); }
.btn-link.danger { color: var(--danger); }
.btn-link:disabled { color: var(--muted); text-decoration: none; }

.trial-panel {
  margin-top: 14px; padding: 14px;
  background: #f7fbff; border: 1px solid #cfe2f7; border-radius: var(--radius);
}
.trial-panel .trial-title { font-weight: 700; margin-bottom: 10px; }
.trial-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
}
.trial-item { background: #fff; border: 1px solid var(--line); border-radius: 6px; padding: 9px 11px; }
.trial-item .label { color: var(--muted); font-size: 12px; }
.trial-item .value { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.trial-item .value.money-big { color: var(--danger); }
.trial-note { margin-top: 9px; font-size: 12px; color: var(--muted); }
.trial-note.warn { color: var(--warn); font-weight: 600; }
.trial-note.error { color: var(--danger); font-weight: 600; }

.form-message {
  margin-top: 12px; padding: 11px 13px; border-radius: 6px;
  border: 1px solid transparent; white-space: pre-wrap; font-weight: 600;
}
.form-message[hidden] { display: none; }
.form-message.error { background: var(--danger-bg); border-color: #f0b4b4; color: var(--danger); }
.form-message.ok { background: var(--ok-bg); border-color: #b8dfc4; color: var(--ok); }
.form-message.info { background: var(--blue-bg); border-color: #c2d8ef; color: var(--brand); }

.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 700; white-space: nowrap;
}
.badge-pending { background: var(--blue-bg); color: var(--brand); }
.badge-success { background: var(--ok-bg); color: var(--ok); }
.badge-failed { background: var(--danger-bg); color: var(--danger); }
.badge-refunded { background: #eef0f3; color: #4b5563; }
.badge-attention { background: #ffe1e1; color: #9b1c1c; border: 1px solid #efb1b1; }
.badge-pdf-generating { background: var(--warn-bg); color: var(--warn); border: 1px solid #f0d09a; }

.modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal[hidden] { display: none; }
.modal-mask { position: absolute; inset: 0; background: rgba(15, 23, 42, 0.45); }
.modal-box {
  position: relative; width: min(520px, 100%);
  max-height: 90vh; overflow: auto;
  background: #fff; border-radius: 10px; box-shadow: 0 20px 40px rgba(15, 23, 42, 0.25);
  padding: 20px;
}
.modal-box h3 { font-size: 18px; margin-bottom: 12px; }
.modal-alert {
  padding: 9px 11px; border-radius: 6px; margin-bottom: 12px;
  background: var(--danger-bg); color: var(--danger); font-weight: 600; font-size: 13px;
}
.confirm-list {
  display: grid; grid-template-columns: 110px 1fr;
  gap: 8px 12px; margin: 0 0 18px;
}
.confirm-list dt { color: var(--muted); }
.confirm-list dd { margin: 0; font-weight: 600; word-break: break-all; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }

.toast {
  position: fixed; right: 22px; bottom: 22px; z-index: 200;
  max-width: min(440px, calc(100vw - 44px));
  padding: 12px 16px; border-radius: 8px;
  background: #1f2937; color: #fff; font-weight: 600;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.25);
  white-space: pre-wrap;
}
.toast.error { background: #9b1c1c; }
.toast.ok { background: #146c3a; }
.toast[hidden] { display: none; }

.operator-badge {
  display: inline-flex; align-items: center;
  padding: 4px 10px; border-radius: 999px;
  background: var(--ok-bg); color: var(--ok);
  font-weight: 700; font-size: 12px; white-space: nowrap;
}
.logout-btn { color: var(--danger); text-decoration: none; border: 1px solid #f0b4b4; border-radius: 6px; }
.logout-btn:hover:not(:disabled) { background: var(--danger-bg); }

.login-main {
  display: block;
  max-width: 460px;
  margin: 54px auto 0;
  padding: 0 24px 32px;
}
.login-card { padding: 24px; }
.login-form { display: flex; flex-direction: column; gap: 14px; margin-top: 4px; }
.login-form .field input { width: 100%; height: 40px; }
.login-btn { width: 100%; min-height: 42px; margin-top: 2px; }
.login-foot { margin-top: 16px; color: var(--muted); font-size: 12px; line-height: 1.7; }

@media (max-width: 720px) {
  .topbar, main { padding-left: 12px; padding-right: 12px; }
  .low-balance-bar, .attention-banner, .policy-banner { margin-left: 12px; margin-right: 12px; }
  .card { padding: 14px; }
  .balance-box { width: 100%; }
  .login-main { margin-top: 24px; padding-left: 12px; padding-right: 12px; }
  .login-card { padding: 18px; }
}
