/* ========== Global ========== */
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; }

#app { min-height: 100vh; display: flex; }

/* ========== Layout ========== */
.app-shell { display: flex; width: 100%; min-height: 100vh; }
.sidebar {
  width: 240px;
  background: linear-gradient(180deg, #0d2c6e 0%, #1455e5 100%);
  color: #fff;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
  flex-shrink: 0;
}
.sidebar-brand {
  padding: 18px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  display: flex; align-items: center; gap: 10px;
}
.sidebar-brand .logo {
  width: 36px; height: 36px; border-radius: 8px;
  background: rgba(255,255,255,0.15);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 18px;
}
.sidebar-brand .title { font-size: 16px; font-weight: 600; }
.sidebar-brand .subtitle { font-size: 11px; color: rgba(255,255,255,0.65); margin-top: 2px; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 12px 8px; }
.sidebar-section { color: rgba(255,255,255,0.45); font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; padding: 12px 12px 6px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 8px; cursor: pointer;
  color: rgba(255,255,255,0.85); font-size: 13.5px; margin: 2px 0;
  transition: background 0.15s, color 0.15s;
}
.nav-item:hover { background: rgba(255,255,255,0.08); color: #fff; }
.nav-item.active { background: rgba(255,255,255,0.18); color: #fff; font-weight: 500; }
.nav-item .icon { width: 18px; height: 18px; flex-shrink: 0; }
.nav-item .badge {
  margin-left: auto; background: #f59e0b; color: #fff;
  border-radius: 999px; padding: 1px 7px; font-size: 11px; font-weight: 600;
}

.sidebar-footer { padding: 12px 16px; border-top: 1px solid rgba(255,255,255,0.08); font-size: 12px; color: rgba(255,255,255,0.6); }
.user-pill { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: linear-gradient(135deg, #5b97ff, #1455e5);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 13px;
}

/* ========== Main ========== */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  min-height: 56px; background: #fff; border-bottom: 1px solid #e2e8f0;
  display: flex; align-items: center; padding: 10px 24px; gap: 16px; flex-wrap: wrap;
  position: sticky; top: 0; z-index: 10;
}
.topbar .crumbs { color: #64748b; font-size: 13px; white-space: nowrap; }
.topbar .crumbs .sep { margin: 0 8px; color: #cbd5e1; }
.topbar .crumbs .current { color: #0f172a; font-weight: 500; }
.topbar .spacer { flex: 1; }
.role-switch {
  display: flex; gap: 4px; background: #f1f5f9; padding: 3px; border-radius: 8px; flex-shrink: 0;
}
.role-switch button {
  border: none; background: transparent; padding: 5px 12px; border-radius: 6px;
  font-size: 12px; color: #475569; cursor: pointer; white-space: nowrap;
}
.role-switch button.active { background: #fff; color: #0d2c6e; box-shadow: 0 1px 2px rgba(0,0,0,0.08); font-weight: 500; }

.content { flex: 1; padding: 24px; overflow-x: auto; }
.page-header { display: flex; align-items: flex-end; justify-content: space-between; margin-bottom: 20px; gap: 16px; flex-wrap: wrap; }
.page-header h1 { font-size: 22px; font-weight: 600; color: #0f172a; margin: 0; }
.page-header .desc { color: #64748b; font-size: 13px; margin-top: 4px; }

/* ========== Cards ========== */
.card {
  background: #fff; border: 1px solid #e2e8f0; border-radius: 12px;
  box-shadow: 0 1px 2px rgba(15,23,42,0.04);
}
.card-header { padding: 16px 20px; border-bottom: 1px solid #e2e8f0; display: flex; align-items: center; justify-content: space-between; }
.card-header h3 { font-size: 15px; font-weight: 600; color: #0f172a; margin: 0; }
.card-body { padding: 20px; }

/* KPI cards */
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 20px; }
@media (max-width: 1100px) { .kpi-grid { grid-template-columns: repeat(2, 1fr); } }
.kpi {
  background: #fff; border: 1px solid #e2e8f0; border-radius: 12px;
  padding: 16px 18px; position: relative; overflow: hidden; min-height: 110px;
}
.kpi .label { color: #64748b; font-size: 12.5px; padding-right: 44px; }
.kpi .value { font-size: 22px; font-weight: 600; color: #0f172a; margin-top: 6px; line-height: 1.2; word-break: break-all; }
.kpi .sub { color: #94a3b8; font-size: 11.5px; margin-top: 4px; }
.kpi .ico {
  position: absolute; right: 14px; top: 14px;
  width: 32px; height: 32px; border-radius: 8px; display: flex; align-items: center; justify-content: center;
  font-size: 14px;
}
.kpi.blue .ico { background: #dbeafe; color: #1455e5; }
.kpi.green .ico { background: #dcfce7; color: #15803d; }
.kpi.amber .ico { background: #fef3c7; color: #b45309; }
.kpi.red .ico { background: #fee2e2; color: #b91c1c; }
.kpi.violet .ico { background: #ede9fe; color: #6d28d9; }

/* 保证金「按订单汇总」可展开行 */
.row-toggle { cursor: pointer; }
.row-toggle:hover { background: #f8fafc; }

/* ========== Tables ========== */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; table-layout: auto; }
table.data.fixed { table-layout: fixed; }
table.data thead th {
  background: #f8fafc; color: #475569; font-weight: 500; text-align: left;
  padding: 10px 12px; border-bottom: 1px solid #e2e8f0; white-space: nowrap;
  font-size: 12.5px;
}
table.data tbody td { padding: 11px 12px; border-bottom: 1px solid #f1f5f9; color: #1e293b; vertical-align: middle; }
table.data tbody td .input { min-width: 100px; }
table.data tbody tr:hover { background: #f8fafc; }
table.data tbody tr:last-child td { border-bottom: none; }
table.data .num { text-align: right; font-variant-numeric: tabular-nums; }
table.data .center { text-align: center; }

/* Status pills */
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 500; line-height: 1.5; }
.pill-gray { background: #f1f5f9; color: #475569; }
.pill-blue { background: #dbeafe; color: #1455e5; }
.pill-green { background: #dcfce7; color: #15803d; }
.pill-amber { background: #fef3c7; color: #b45309; }
.pill-red { background: #fee2e2; color: #b91c1c; }
.pill-violet { background: #ede9fe; color: #6d28d9; }
.pill-cyan { background: #cffafe; color: #0e7490; }

/* ========== Buttons ========== */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px; border-radius: 8px; font-size: 13px; font-weight: 500;
  border: 1px solid transparent; cursor: pointer; transition: all 0.15s;
  white-space: nowrap;
}
.btn-primary { background: #1455e5; color: #fff; }
.btn-primary:hover { background: #0d43b8; }
.btn-secondary { background: #fff; color: #334155; border-color: #cbd5e1; }
.btn-secondary:hover { background: #f8fafc; border-color: #94a3b8; }
.btn-ghost { background: transparent; color: #475569; }
.btn-ghost:hover { background: #f1f5f9; }
.btn-danger { background: #dc2626; color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-success { background: #16a34a; color: #fff; }
.btn-success:hover { background: #15803d; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-xs { padding: 2px 7px; font-size: 11px; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

/* ========== Form ========== */
.form-row { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px 16px; }
.form-row.cols-3 { grid-template-columns: repeat(3, 1fr); }
.form-row.cols-4 { grid-template-columns: repeat(4, 1fr); }
.form-row.cols-1 { grid-template-columns: 1fr; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 4px; }
.field label { font-size: 12px; color: #475569; font-weight: 500; }
.field .req::after { content: " *"; color: #dc2626; }
.input, .select, .textarea {
  border: 1px solid #cbd5e1; border-radius: 7px; padding: 7px 10px; font-size: 13px;
  background: #fff; color: #0f172a; width: 100%; transition: border-color 0.15s, box-shadow 0.15s;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: #2f74ff; box-shadow: 0 0 0 3px rgba(47,116,255,0.12);
}
.textarea { min-height: 70px; resize: vertical; font-family: inherit; }
.input[readonly] { background: #f8fafc; color: #475569; }
.field .hint { font-size: 11px; color: #94a3b8; }

/* ========== Modal ========== */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15,23,42,0.5);
  z-index: 100; display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 16px; overflow-y: auto;
}
.modal {
  background: #fff; border-radius: 12px; width: 100%; max-width: 900px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.25);
  display: flex; flex-direction: column; max-height: calc(100vh - 80px);
}
.modal.large { max-width: 1100px; }
.modal-header { padding: 16px 20px; border-bottom: 1px solid #e2e8f0; display: flex; align-items: center; justify-content: space-between; }
.modal-header h3 { font-size: 16px; font-weight: 600; margin: 0; }
.modal-body { padding: 20px; overflow-y: auto; flex: 1; }
.modal-footer { padding: 12px 20px; border-top: 1px solid #e2e8f0; display: flex; justify-content: flex-end; gap: 8px; background: #f8fafc; border-radius: 0 0 12px 12px; }
.icon-btn { background: transparent; border: none; cursor: pointer; color: #64748b; padding: 4px; border-radius: 6px; }
.icon-btn:hover { background: #f1f5f9; color: #0f172a; }

/* ========== Toolbars ========== */
.toolbar { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar .grow { flex: 1; }
.toolbar .input { width: 220px; }
.toolbar select.input { width: 150px; }

/* ========== Tabs ========== */
.tabs { display: flex; border-bottom: 1px solid #e2e8f0; margin-bottom: 16px; }
.tabs .tab { padding: 9px 16px; cursor: pointer; font-size: 13.5px; color: #64748b; border-bottom: 2px solid transparent; }
.tabs .tab.active { color: #1455e5; border-color: #1455e5; font-weight: 500; }
.tabs .tab:hover:not(.active) { color: #0f172a; }

/* ========== Misc ========== */
.empty { text-align: center; padding: 48px 16px; color: #94a3b8; font-size: 13px; }
.empty .em-icon { font-size: 36px; margin-bottom: 8px; opacity: 0.6; }
.divider { height: 1px; background: #e2e8f0; margin: 12px 0; }
.text-muted { color: #64748b; }
.text-mono { font-family: "SF Mono", Menlo, Consolas, monospace; font-size: 12px; }
.tag-link { color: #1455e5; cursor: pointer; text-decoration: none; }
.tag-link:hover { text-decoration: underline; }
.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.gap-1 { gap: 4px; } .gap-2 { gap: 8px; } .gap-3 { gap: 12px; } .gap-4 { gap: 16px; }
.items-center { align-items: center; } .justify-between { justify-content: space-between; }
.text-right { text-align: right; }
.text-xs { font-size: 11px; } .text-sm { font-size: 13px; }
.font-bold { font-weight: 600; }
.mb-2 { margin-bottom: 8px; } .mb-3 { margin-bottom: 12px; } .mb-4 { margin-bottom: 16px; }
.mt-2 { margin-top: 8px; } .mt-3 { margin-top: 12px; } .mt-4 { margin-top: 16px; }

/* Link button */
.link { color: #1455e5; cursor: pointer; }
.link:hover { text-decoration: underline; }

/* Amount colors */
.amount-positive { color: #15803d; font-weight: 500; }
.amount-negative { color: #b91c1c; font-weight: 500; }
.amount-zero { color: #94a3b8; }

/* info card */
.info-card { background: #eff6ff; border: 1px solid #bfdbfe; color: #1e40af; padding: 10px 14px; border-radius: 8px; font-size: 12.5px; display: flex; gap: 8px; }
.warn-card { background: #fffbeb; border: 1px solid #fde68a; color: #92400e; padding: 10px 14px; border-radius: 8px; font-size: 12.5px; display: flex; gap: 8px; }
.danger-card { background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; padding: 10px 14px; border-radius: 8px; font-size: 12.5px; display: flex; gap: 8px; }
.success-card { background: #f0fdf4; border: 1px solid #bbf7d0; color: #14532d; padding: 10px 14px; border-radius: 8px; font-size: 12.5px; display: flex; gap: 8px; }

/* order detail summary */
.summary-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.summary-item { background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 8px; padding: 10px 12px; }
.summary-item .l { font-size: 11.5px; color: #64748b; }
.summary-item .v { font-size: 18px; font-weight: 600; color: #0f172a; margin-top: 2px; }

/* Two-column form layout for modals */
.split-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 768px) { .split-2 { grid-template-columns: 1fr; } }

/* Stepper for order workflow */
.stepper { display: flex; align-items: center; gap: 4px; padding: 8px 0; }
.step { display: flex; align-items: center; gap: 6px; font-size: 12px; color: #94a3b8; }
.step .dot { width: 20px; height: 20px; border-radius: 50%; background: #e2e8f0; color: #94a3b8; display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 600; }
.step.done .dot { background: #16a34a; color: #fff; }
.step.active .dot { background: #1455e5; color: #fff; }
.step.done, .step.active { color: #0f172a; }
.step .bar { width: 30px; height: 2px; background: #e2e8f0; }
.step.done + .step .bar, .step.done .bar { background: #16a34a; }

/* Toast */
.toast-wrap { position: fixed; top: 70px; right: 24px; z-index: 1000; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #0f172a; color: #fff; padding: 10px 14px; border-radius: 8px; font-size: 13px; box-shadow: 0 8px 20px rgba(0,0,0,0.2); min-width: 240px; display: flex; align-items: center; gap: 8px; animation: slideIn 0.2s; }
.toast.success { background: #15803d; }
.toast.error { background: #b91c1c; }
.toast.warn { background: #b45309; }
@keyframes slideIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: translateX(0); } }

/* Charts */
.chart { width: 100%; height: 280px; }
.chart.tall { height: 320px; }

/* Page two-col layout */
.split-page { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 1100px) { .split-page { grid-template-columns: 1fr; } }

/* ========== Responsive ==========
   只调整排版，不改任何业务逻辑。
   窄屏下最常见的问题：宽表格被压缩 → 中文列被逐字挤成竖排，
   这里改成「表格保持自身最小宽度 + .table-wrap 横向滚动」。
   ====================================== */
@media (max-width: 1100px) {
  /* 表格单元格不主动换行：避免「云南东辉新能源开发有限公司」被压成一列一个字 */
  table.data tbody td { white-space: nowrap; }
  .summary-grid { grid-template-columns: repeat(2, 1fr); }
  .content { padding: 16px; }
  .kpi-grid { gap: 12px; }
  .stepper { overflow-x: auto; padding-bottom: 4px; }
}

@media (max-width: 900px) {
  .sidebar { width: 184px; }
  .sidebar-brand { padding: 14px; }
  .sidebar-nav { padding: 10px 6px; }
  .topbar { padding: 10px 16px; }
  .page-header h1 { font-size: 19px; }
  .page-header .desc { font-size: 12.5px; }
  .card-body { padding: 14px; }
  .card-header { padding: 14px 16px; }

  /* 表单改单列，避免输入框被压到不可用 */
  .form-row, .form-row.cols-3, .form-row.cols-4 { grid-template-columns: 1fr; }

  /* 工具栏：搜索/筛选独占一行，不再固定 220px 溢出 */
  .toolbar .input, .toolbar select.input { width: 100%; }
  .toolbar .grow { flex-basis: 100%; }

  /* Tab 条横向可滑（保证金页有 6 个 Tab） */
  .tabs { overflow-x: auto; }
  .tabs .tab { padding: 9px 12px; white-space: nowrap; }

  /* 弹窗占满可用宽度 */
  .modal, .modal.large { max-width: 100%; }
  .modal-backdrop { padding: 20px 10px; }
  .modal-header, .modal-body { padding-left: 14px; padding-right: 14px; }

  /* Toast 不再溢出屏幕 */
  .toast-wrap { left: 10px; right: 10px; }
  .toast { min-width: 0; width: 100%; }
}

@media (max-width: 620px) {
  /* 侧边栏收成图标条 */
  .sidebar { width: 56px; }
  .sidebar-brand { padding: 12px 0; justify-content: center; }
  .sidebar-brand > div:not(.logo) { display: none; }
  .sidebar-section { display: none; }
  .nav-item { justify-content: center; padding: 10px 0; }
  .nav-item > span:not(.icon) { display: none; }
  .sidebar-footer { display: none; }

  .content { padding: 10px; }
  .kpi-grid { grid-template-columns: 1fr; }
  .summary-grid { grid-template-columns: 1fr; }
  .kpi { min-height: 92px; padding: 12px 14px; }
  .kpi .value { font-size: 19px; }
  .modal-backdrop { padding: 10px 6px; }
}
