:root {
  --bg-from: #f8fafc;
  --bg-via: rgba(239, 246, 255, 0.5);
  --bg-to: rgba(238, 242, 255, 0.6);
  --text: #0f172a;
  --text-muted: #64748b;
  --text-soft: #94a3b8;
  --border: #e2e8f0;
  --border-soft: #f1f5f9;
  --card-bg: #ffffff;
  --primary: #2563eb;
  --primary-2: #4f46e5;
  --primary-700: #1d4ed8;
  --indigo-700: #4338ca;
  --green: #16a34a;
  --green-700: #15803d;
  --red: #dc2626;
  --red-500: #ef4444;
  --red-700: #b91c1c;
  --amber: #d97706;
  --rose: #f43f5e;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.05), 0 1px 2px rgba(15, 23, 42, 0.04);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-xs: 6px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  color: var(--text);
  background: linear-gradient(135deg, var(--bg-from), var(--bg-via), var(--bg-to));
  min-height: 100vh;
}

.hidden { display: none !important; }

.container {
  max-width: 1440px;
  margin: 0 auto;
  padding: 0 24px;
}

/* Header */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 16px;
  padding-bottom: 16px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}
.brand-icon {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 16px rgba(37, 99, 235, 0.25);
}
.brand-title {
  font-size: 18px;
  font-weight: 700;
  margin: 0;
  color: var(--text);
}
.brand-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin: 2px 0 0;
}

/* Layout */
.main-area { padding: 24px 24px 48px; }

.grid-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr);
  gap: 24px;
}
@media (max-width: 900px) {
  .grid-layout { grid-template-columns: 1fr; }
}

.form-column, .result-column {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Card */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.card-header {
  padding: 20px 24px 12px;
}
.card-title {
  font-size: 15px;
  font-weight: 600;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}
.card-desc {
  font-size: 12px;
  color: var(--text-muted);
  margin: 6px 0 0;
}
.card-body { padding: 12px 24px 20px; }

/* Footer */
.site-footer {
  border-top: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.6);
  margin-top: 48px;
  padding: 16px 0;
  text-align: center;
}
.site-footer p {
  font-size: 12px;
  color: var(--text-soft);
  margin: 0;
}

/* Form */
.form-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.form-grid-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 12px;
}
@media (max-width: 600px) {
  .form-grid-2, .form-grid-3 { grid-template-columns: 1fr; }
}
.field { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.field:last-child { margin-bottom: 0; }
.label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.label-sm { font-size: 12px; color: var(--text-muted); font-weight: 500; }
.help-icon {
  width: 14px; height: 14px; color: var(--text-soft); cursor: help;
  position: relative;
}
.help-icon[data-tip]:hover::after {
  content: attr(data-tip);
  position: absolute;
  bottom: 130%;
  left: 50%;
  transform: translateX(-50%);
  background: #1e293b;
  color: #fff;
  font-size: 11px;
  padding: 6px 10px;
  border-radius: 6px;
  white-space: normal;
  width: 220px;
  z-index: 100;
  font-weight: 400;
  line-height: 1.4;
}
.input, .select {
  width: 100%;
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  font-size: 13px;
  color: var(--text);
  background: #fff;
  transition: border 0.15s, box-shadow 0.15s;
  font-family: inherit;
}
.input:focus, .select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}
.input:disabled, .select:disabled {
  background: #f8fafc;
  color: var(--text-soft);
  cursor: not-allowed;
}
.input-prefix-wrap {
  position: relative;
}
.input-prefix-wrap .input { padding-left: 32px; }
.input-prefix-wrap .input.with-suffix { padding-right: 28px; }
.input-prefix-wrap .input.pl-10 { padding-left: 42px; }
.input-prefix {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 13px;
  color: var(--text-soft);
}
.input-suffix {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 12px;
  color: var(--text-soft);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 38px;
  padding: 0 16px;
  border-radius: var(--radius-xs);
  font-size: 13px;
  font-weight: 500;
  border: 1px solid transparent;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s, border 0.15s, opacity 0.15s;
  background: transparent;
  color: var(--text);
  text-decoration: none;
}
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-sm { height: 30px; padding: 0 12px; font-size: 12px; }
.btn-lg { height: 44px; padding: 0 22px; font-size: 14px; }
.btn-outline { border-color: var(--border); background: #fff; }
.btn-outline:hover:not(:disabled) { background: #f8fafc; }
.btn-primary {
  color: #fff;
  background: linear-gradient(90deg, var(--primary), var(--primary-2));
  box-shadow: 0 6px 16px rgba(37, 99, 235, 0.25);
}
.btn-primary:hover:not(:disabled) {
  background: linear-gradient(90deg, var(--primary-700), var(--indigo-700));
}
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover:not(:disabled) { background: var(--red-700); }

/* Action row */
.actions-row { display: flex; gap: 12px; }
.actions-row .btn-primary { flex: 1; }

/* Result */
.result-summary {
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  text-align: center;
}
.result-summary.profit-positive {
  border-color: #bbf7d0;
  background: linear-gradient(135deg, #f0fdf4, #ecfdf5);
}
.result-summary.profit-negative {
  border-color: #fecaca;
  background: linear-gradient(135deg, #fef2f2, #fff1f2);
}
.result-summary .label {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
}
.result-amount {
  font-size: 30px;
  font-weight: 700;
  margin: 6px 0;
}
.result-amount.green { color: var(--green-700); }
.result-amount.red { color: var(--red); }
.result-badges {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  margin-top: 6px;
}
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 500;
  padding: 3px 8px;
  border-radius: 999px;
  background: #0f172a;
  color: #fff;
  border: 1px solid transparent;
}
.badge-outline {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}
.badge-destructive { background: var(--red); }
.badge-warn {
  background: transparent;
  color: var(--amber);
  border-color: #fcd34d;
}

/* Price overview */
.kv-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  margin: 4px 0;
}
.kv-row .muted { color: var(--text-muted); }
.kv-row .small { font-size: 12px; color: var(--text-soft); }
.kv-row .value { font-weight: 600; }
.kv-row .value.blue { color: var(--primary); }
.kv-row .value.red { color: var(--red-500); }
.kv-row .value.amber { color: var(--amber); }
.divider {
  height: 1px;
  background: var(--border);
  margin: 10px 0;
  border: none;
}

/* Fee breakdown */
.fee-item { padding: 6px 0; border-bottom: 1px solid var(--border-soft); }
.fee-item:last-child { border-bottom: none; }
.fee-name { font-size: 13px; font-weight: 500; }
.fee-amount { font-size: 13px; font-weight: 600; }
.fee-formula { font-size: 11px; color: var(--text-soft); line-height: 1.4; margin-top: 4px; }

/* Empty state */
.empty {
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  background: #fff;
  padding: 64px 20px;
  text-align: center;
}
.empty-icon {
  width: 64px;
  height: 64px;
  border-radius: 999px;
  background: #f1f5f9;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
  color: #cbd5e1;
}
.empty-title { font-size: 13px; font-weight: 500; color: var(--text-muted); }
.empty-sub { font-size: 12px; color: var(--text-soft); margin-top: 4px; }
.empty-flow {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-soft);
  margin-top: 16px;
}
.empty-flow .accent { color: var(--primary); font-weight: 500; }

/* Error */
.error-card {
  border: 1px solid #fecaca;
  background: #fef2f2;
  color: var(--red-700);
  border-radius: var(--radius);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

/* Oversized in result */
.oversize-warn {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: var(--red-700);
  border-radius: var(--radius-xs);
  padding: 12px;
}
.oversize-warn .head {
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}
.oversize-warn ul { margin: 4px 0 0 22px; padding: 0; font-size: 12px; }

/* Rules panel */
.rules-panel {
  background: rgba(239, 246, 255, 0.5);
  border: 1px solid #bfdbfe;
  border-radius: var(--radius);
  margin-bottom: 24px;
  padding: 16px 24px 20px;
}
.rules-panel h2 {
  font-size: 15px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
}
.rules-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 12px;
}
@media (max-width: 700px) { .rules-grid { grid-template-columns: 1fr; } }
.rules-grid h4 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0 0 4px;
}
.rules-grid p {
  font-size: 12px;
  color: var(--text-muted);
  margin: 0;
  line-height: 1.5;
}
.rules-grid p .blue { color: var(--primary); font-weight: 600; }

/* Tier table */
.tier-table-wrap { overflow-x: auto; margin-top: 12px; }
.tier-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.tier-table th, .tier-table td {
  border: 1px solid #bfdbfe;
  padding: 6px 8px;
  text-align: left;
  vertical-align: top;
}
.tier-table thead { background: rgba(191, 219, 254, 0.6); }
.tier-table th { font-weight: 600; }
.tier-table tbody tr:hover { background: rgba(239, 246, 255, 0.6); }
.tier-table .formula { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

/* Dialog */
.dialog-mask {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.dialog {
  background: #fff;
  border-radius: var(--radius);
  padding: 20px;
  max-width: 460px;
  width: 100%;
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.18);
}
.dialog-danger {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: var(--red-700);
}
.dialog-title {
  font-size: 16px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 12px;
}
.dialog-body { font-size: 13px; line-height: 1.6; }
.dialog-body ul { margin: 8px 0 0 20px; padding: 0; }
.dialog-footer { display: flex; justify-content: flex-end; margin-top: 16px; }

/* Tier editor */
.tier-editor {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin-bottom: 8px;
}
.tier-editor-head {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: #f8fafc;
  border: none;
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
}
.tier-editor-head:hover { background: #f1f5f9; }
.tier-editor-body { display: none; padding: 12px; background: #fff; }
.tier-editor.open .tier-editor-body { display: block; }
.tier-editor.open .tier-editor-head .chevron { transform: rotate(180deg); }
.chevron { transition: transform 0.15s; }


/* ===== New layout: 4-col grid, hint banner, warn card ===== */
.header-actions { display: flex; gap: 8px; }

.form-grid-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 12px;
}
@media (max-width: 900px) {
  .form-grid-4 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 600px) {
  .form-grid-4 { grid-template-columns: 1fr; }
}
.form-grid-4 .field { margin-bottom: 0; }

.hint-banner {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  color: #1e40af;
  border-radius: var(--radius-xs);
  padding: 8px 12px;
  font-size: 12px;
  margin: 12px 0 12px;
  display: flex;
  align-items: center;
  gap: 6px;
  line-height: 1.5;
}

.warn-card {
  margin-top: 12px;
  background: #fffbeb;
  border: 1px solid #fcd34d;
  color: #92400e;
  border-radius: var(--radius-xs);
  padding: 10px 12px;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 12px;
  line-height: 1.55;
}
.warn-card svg { flex-shrink: 0; margin-top: 2px; color: #d97706; }
.warn-card strong { color: #78350f; display: block; margin-bottom: 2px; font-size: 13px; }
.warn-card p { margin: 0; }
.warn-card b { color: #b45309; }

.readonly-rate {
  height: 38px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-xs);
  padding: 0 12px;
  display: flex;
  align-items: center;
  font-size: 13px;
  font-weight: 600;
  background: #f8fafc;
  color: var(--primary);
}
.readonly-rate.has-value { border-style: solid; border-color: #bfdbfe; background: #eff6ff; }
.readonly-rate .muted-text { color: var(--text-soft); font-weight: 400; font-size: 12px; }

/* ===== Dialog large + close button ===== */
.dialog-large {
  max-width: 900px;
  background: #fff;
  color: var(--text);
}
.dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.dialog-title-default {
  font-size: 16px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  color: var(--text);
}
.dialog-close {
  background: transparent;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--text-muted);
  width: 28px;
  height: 28px;
  border-radius: 6px;
  line-height: 1;
}
.dialog-close:hover { background: #f1f5f9; color: var(--text); }

/* ===== Query dialog ===== */
.query-toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.query-toolbar .input { flex: 1; min-width: 200px; }
.query-toolbar .select { width: 200px; }
.upload-btn { cursor: pointer; }
.query-help {
  font-size: 11px;
  color: var(--text-muted);
  background: #f8fafc;
  border-radius: 6px;
  padding: 8px 10px;
  line-height: 1.6;
  margin: 8px 0 12px;
}
.query-help b { color: var(--primary); font-weight: 500; }
.query-help a { color: var(--primary); text-decoration: underline; margin-left: 4px; }
.query-table-wrap {
  max-height: 50vh;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
}
.query-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.query-table th, .query-table td {
  border-bottom: 1px solid var(--border-soft);
  padding: 6px 10px;
  text-align: left;
  white-space: nowrap;
}
.query-table thead th {
  background: #f8fafc;
  position: sticky;
  top: 0;
  font-weight: 600;
  z-index: 1;
}
.query-table tbody tr:hover { background: #eff6ff; }
.query-table .rate-cell.has { color: var(--primary); font-weight: 500; text-align: center; }
.query-table .rate-cell.na { color: var(--text-soft); text-align: center; }
.query-table .empty-row { text-align: center; color: var(--text-soft); padding: 24px; }
.query-foot { font-size: 11px; color: var(--text-soft); margin: 6px 0 0; }

/* ===== 5-col grid for second row (汇率/方案/大类目/子类目/查询佣金率) ===== */
.form-grid-5 {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 12px;
}
.form-grid-5 .field { margin-bottom: 0; }
@media (max-width: 1100px) {
  .form-grid-5 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 600px) {
  .form-grid-5 { grid-template-columns: 1fr; }
}

/* ===== Wider dialog for the new 8-col query table ===== */
.dialog-large { max-width: 1100px; }

/* ===== Grouped query table (price brackets × 2 plans) ===== */
.query-table-grouped th.bracket-head {
  background: #eff6ff;
  color: #1e40af;
  border-bottom: 1px solid var(--border);
}
.query-table-grouped th.plan-head {
  font-weight: 500;
  font-size: 11px;
  color: var(--text-muted);
  background: #f8fafc;
}
.query-table-grouped td.rate-cell.rfbs { background: rgba(239, 246, 255, 0.45); }
.query-table-grouped td.rate-cell.fbp { background: rgba(255, 255, 255, 1); }
.query-table th, .query-table td { text-align: center; }
.query-table th:nth-child(1), .query-table td:nth-child(1),
.query-table th:nth-child(2), .query-table td:nth-child(2) { text-align: left; }
