/* ================= 设计变量 ================= */
:root {
  --brand: #1f6feb;
  --brand-dark: #1858c4;
  --brand-soft: #eaf2ff;
  --ink: #16202c;
  --ink-2: #4a5a6a;
  --ink-3: #7d8a99;
  --line: #e3e8ef;
  --line-2: #f1f4f8;
  --bg: #f5f7fa;
  --card: #ffffff;
  --ok: #12a150;
  --ok-soft: #e6f7ee;
  --warn: #d98216;
  --warn-soft: #fdf3e3;
  --danger: #d9403b;
  --danger-soft: #fdeceb;
  --info: #6b56d6;
  --info-soft: #f0edfd;
  --radius: 10px;
  --radius-lg: 16px;
  --shadow: 0 1px 2px rgba(16, 32, 48, 0.06), 0 6px 20px rgba(16, 32, 48, 0.06);
  --shadow-lg: 0 12px 40px rgba(16, 32, 48, 0.18);
  --sidebar-w: 226px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC",
    "Hiragino Sans GB", "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; }

/* ================= 登录页 ================= */
.login-screen {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(1200px 600px at 15% 0%, #dbe8ff 0%, transparent 55%),
    radial-gradient(900px 500px at 100% 100%, #e4f6ef 0%, transparent 50%), var(--bg);
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 28px 26px 22px;
  display: grid;
  gap: 14px;
}
.login-brand { display: flex; gap: 12px; align-items: center; margin-bottom: 6px; }
.login-brand h1 { font-size: 18px; }
.login-brand p { margin: 3px 0 0; font-size: 12px; color: var(--ink-3); }
.brand-mark {
  width: 42px; height: 42px; flex: none;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--brand), #4b93ff);
  color: #fff; font-weight: 700;
  display: grid; place-items: center; font-size: 20px;
}
.brand-mark.small { width: 34px; height: 34px; font-size: 16px; border-radius: 10px; }
.login-tip { font-size: 12px; color: var(--ink-3); margin: 0; line-height: 1.6; }

/* ================= 布局 ================= */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w);
  flex: none;
  background: #fff;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar-head {
  display: flex; gap: 10px; align-items: center;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--line-2);
}
.sidebar-title { display: grid; gap: 2px; min-width: 0; }
.sidebar-title strong { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-title span { font-size: 11px; color: var(--brand); background: var(--brand-soft); border-radius: 20px; padding: 1px 8px; width: fit-content; }
.nav { padding: 10px 8px; display: grid; gap: 2px; overflow-y: auto; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 8px;
  color: var(--ink-2); font-size: 13.5px; cursor: pointer;
  border: none; background: none; width: 100%; text-align: left; font-family: inherit;
}
.nav-item:hover { background: var(--line-2); color: var(--ink); }
.nav-item.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.nav-ico { width: 18px; text-align: center; font-size: 15px; }
.nav-group { font-size: 11px; color: var(--ink-3); padding: 12px 12px 4px; letter-spacing: 0.4px; }
.sidebar-foot { padding: 12px; border-top: 1px solid var(--line-2); display: grid; gap: 8px; }
.side-user { font-size: 12px; color: var(--ink-2); line-height: 1.5; }
.side-user strong { display: block; font-size: 13px; color: var(--ink); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 56px; flex: none;
  background: #fff; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 12px;
  padding: 0 20px; position: sticky; top: 0; z-index: 20;
}
.topbar h2 { font-size: 16px; flex: 1; }
.topbar-right { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.view { padding: 20px; display: grid; gap: 16px; align-content: start; }
.icon-btn {
  display: none;
  border: 1px solid var(--line); background: #fff; border-radius: 8px;
  width: 34px; height: 34px; font-size: 16px; cursor: pointer; color: var(--ink-2);
}
.scrim { display: none; }

/* ================= 组件 ================= */
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
}
.card-head {
  padding: 13px 16px; border-bottom: 1px solid var(--line-2);
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
.card-head h3 { font-size: 14.5px; flex: 1; }
.card-body { padding: 16px; }
.card-body.tight { padding: 0; }
.muted { color: var(--ink-3); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.center { text-align: center; }
.grid { display: grid; gap: 14px; }
.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
/* 自适应列数：每列不少于 240px，放不下就自动减少列数，任何宽度都不会挤出容器 */
.grid-auto { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; }

/* 统计卡 */
.stat {
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 15px 16px; box-shadow: var(--shadow); display: grid; gap: 6px;
}
.stat .label { font-size: 12.5px; color: var(--ink-3); display: flex; align-items: center; gap: 6px; }
.stat .value { font-size: 23px; font-weight: 700; letter-spacing: -0.4px; }
.stat .value.sm { font-size: 19px; }
.stat .sub { font-size: 12px; color: var(--ink-3); }
.stat.accent { background: linear-gradient(135deg, var(--brand), #4b93ff); border-color: transparent; color: #fff; }
.stat.accent .label, .stat.accent .sub { color: rgba(255, 255, 255, 0.85); }
.stat.warn { background: var(--warn-soft); border-color: #f3dcbb; }
.stat.warn .value { color: var(--warn); }
.stat.danger { background: var(--danger-soft); border-color: #f6d3d1; }
.stat.danger .value { color: var(--danger); }
.stat.ok { background: var(--ok-soft); border-color: #cdeedb; }
.stat.ok .value { color: var(--ok); }

/* 按钮 */
.btn {
  font-family: inherit; font-size: 13px; font-weight: 500;
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  padding: 7px 13px; border-radius: 8px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  white-space: nowrap;
}
.btn:hover { background: var(--line-2); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn-danger { background: #fff; border-color: #f0c8c6; color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn-ghost:hover { background: var(--line-2); }
.btn-sm { padding: 4px 9px; font-size: 12px; border-radius: 7px; }
.btn-lg { padding: 10px 16px; font-size: 15px; }
.btn-block { width: 100%; }

/* 表单 */
.field { display: grid; gap: 5px; min-width: 0; }
.field > span { font-size: 12.5px; color: var(--ink-2); font-weight: 500; }
.field .req::after { content: " *"; color: var(--danger); }
input, select, textarea {
  font-family: inherit; font-size: 13.5px; color: var(--ink);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px;
  background: #fff; width: 100%; min-width: 0;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft);
}
textarea { resize: vertical; min-height: 62px; }
.filters { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.filters .field { min-width: 130px; }

/* 表格 */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
th { font-size: 12.5px; color: var(--ink-3); font-weight: 600; background: #fafbfd; white-space: nowrap; position: sticky; top: 0; }
tbody tr:hover { background: #fafcff; }
tbody tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.total-row td { font-weight: 700; background: #fafbfd; }
.clickable { cursor: pointer; }

/* 徽章 */
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 20px;
  font-size: 11.5px; font-weight: 600; white-space: nowrap; line-height: 1.7;
}
.badge.gray { background: var(--line-2); color: var(--ink-2); }
.badge.blue { background: var(--brand-soft); color: var(--brand); }
.badge.green { background: var(--ok-soft); color: var(--ok); }
.badge.orange { background: var(--warn-soft); color: var(--warn); }
.badge.red { background: var(--danger-soft); color: var(--danger); }
.badge.purple { background: var(--info-soft); color: var(--info); }

/* 提示条 */
.alert { padding: 9px 12px; border-radius: 8px; font-size: 13px; line-height: 1.6; }
.alert-error { background: var(--danger-soft); color: #a32b27; border: 1px solid #f6d3d1; }
.alert-ok { background: var(--ok-soft); color: #0b7a3c; border: 1px solid #cdeedb; }
.alert-info { background: var(--brand-soft); color: #14509f; border: 1px solid #cfe1ff; }
.alert-warn { background: var(--warn-soft); color: #93590b; border: 1px solid #f3dcbb; }

/* 空状态 */
.empty { padding: 44px 20px; text-align: center; color: var(--ink-3); display: grid; gap: 8px; justify-items: center; }
.empty .big { font-size: 34px; opacity: 0.5; }

/* 弹窗 */
.modal-mask {
  position: fixed; inset: 0; background: rgba(16, 28, 44, 0.45);
  display: grid; place-items: start center; padding: 24px 16px; overflow-y: auto; z-index: 100;
  backdrop-filter: blur(2px);
}
.modal {
  background: #fff; border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  width: 100%; max-width: 720px; margin: auto 0; overflow: hidden;
}
.modal.wide { max-width: 940px; }
.modal.narrow { max-width: 460px; }
.modal-head { padding: 15px 18px; border-bottom: 1px solid var(--line-2); display: flex; align-items: center; gap: 10px; }
.modal-head h3 { font-size: 15.5px; flex: 1; }
.modal-body { padding: 18px; display: grid; gap: 14px; max-height: 68vh; overflow-y: auto; }
.modal-foot { padding: 13px 18px; border-top: 1px solid var(--line-2); display: flex; gap: 10px; justify-content: flex-end; background: #fafbfd; }
.x-btn { border: none; background: none; font-size: 20px; color: var(--ink-3); cursor: pointer; line-height: 1; padding: 0 4px; }
.x-btn:hover { color: var(--ink); }

/* 明细行编辑 */
.items-table { width: 100%; border-collapse: collapse; }
.items-table th, .items-table td { padding: 5px 6px; border: none; }
.items-table th { background: none; position: static; font-size: 12px; }
.items-table input, .items-table select { padding: 6px 8px; font-size: 13px; }
.items-table td.act { width: 34px; }
.del-row { border: none; background: none; color: var(--danger); cursor: pointer; font-size: 15px; padding: 4px 6px; border-radius: 6px; }
.del-row:hover { background: var(--danger-soft); }

/* 附件 */
.drop {
  border: 1.5px dashed #c6d3e3; border-radius: var(--radius); padding: 18px;
  text-align: center; color: var(--ink-3); background: #fbfcfe; cursor: pointer;
  font-size: 13px; line-height: 1.7;
}
.drop:hover, .drop.over { border-color: var(--brand); background: var(--brand-soft); color: var(--brand); }
.file-list { display: grid; gap: 8px; }
.file-item {
  display: flex; align-items: center; gap: 10px;
  border: 1px solid var(--line); border-radius: 9px; padding: 9px 12px; background: #fff;
}
.file-ico { font-size: 19px; width: 22px; text-align: center; }
.file-meta { flex: 1; min-width: 0; }
.file-meta strong { display: block; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-meta span { font-size: 11.5px; color: var(--ink-3); }

/* 详情描述列表 */
.dl { display: grid; grid-template-columns: 96px 1fr; gap: 9px 14px; font-size: 13.5px; }
.dl dt { color: var(--ink-3); font-size: 12.5px; }
.dl dd { margin: 0; word-break: break-word; }

/* 月度趋势条 */
.bars { display: flex; align-items: flex-end; gap: 12px; height: 130px; padding: 6px 2px 0; }
.bar-col { flex: 1; display: grid; gap: 6px; justify-items: center; align-content: end; height: 100%; }
.bar {
  width: 100%; max-width: 46px; border-radius: 6px 6px 0 0;
  background: linear-gradient(180deg, #4b93ff, var(--brand)); min-height: 3px;
}
.bar-lbl { font-size: 11px; color: var(--ink-3); white-space: nowrap; }
.bar-val { font-size: 11.5px; font-weight: 600; color: var(--ink-2); }

/* ================= 利润率看板图表 ================= */
.chart {
  display: flex; align-items: flex-end; gap: 14px;
  height: 210px; padding: 8px 4px 0;
}
.chart-col {
  flex: 1; display: grid; grid-template-rows: 20px 1fr 16px 16px;
  gap: 4px; justify-items: center; height: 100%; min-width: 0;
}
.chart-val { font-size: 11.5px; font-weight: 600; color: var(--ink-2); white-space: nowrap; }
.chart-pair {
  display: flex; align-items: flex-end; justify-content: center; gap: 4px;
  width: 100%; height: 100%;
}
.chart-bar {
  width: 40%; max-width: 26px; min-height: 3px;
  border-radius: 5px 5px 0 0; transition: height 0.25s ease;
}
.chart-bar.rev { background: linear-gradient(180deg, #7fb2ff, var(--brand)); }
.chart-bar.pf { background: linear-gradient(180deg, #4bd08a, var(--ok)); }
.chart-bar.ls { background: linear-gradient(180deg, #ef7b77, var(--danger)); }
.chart-lbl { font-size: 11.5px; color: var(--ink-3); white-space: nowrap; }
.chart-margin { font-size: 11px; font-weight: 600; color: var(--ink-2); }

.legend { display: inline-flex; align-items: center; gap: 5px; margin-left: 12px; }
.legend .dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.legend .dot.rev { background: var(--brand); }
.legend .dot.pf { background: var(--ok); }
.legend .dot.ls { background: var(--danger); }

/* ================= 汇率 1 : X 输入 ================= */
/* 设计要点：不强行撑满，靠内容宽度自然排列，避免把右侧币种名挤掉 */
.rate-row {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.rate-row input[type='number'] {
  flex: 0 0 auto; width: 150px; text-align: center; font-weight: 700;
  font-variant-numeric: tabular-nums; font-size: 15px;
}
.rate-side {
  flex: 0 1 auto; min-width: 0;
  font-size: 13px; color: var(--ink-2); white-space: nowrap;
  background: var(--line-2); border-radius: 7px; padding: 8px 12px;
}
.rate-eq { flex: none; font-weight: 700; color: var(--ink-3); }
/* 反向汇率 + 来源说明：占满剩余空间，空间不够时自动换行 */
.rate-note {
  flex: 1 1 240px; min-width: 0;
  font-size: 12px; color: var(--ink-3); line-height: 1.6;
}
/* 设置面板里的汇率行：输入框弹性宽度，最小 72px，窄屏也能自适应 */
.rate-row.compact input[type='number'] { width: auto; min-width: 72px; max-width: 120px; flex: 1 1 72px; }

@media (max-width: 780px) {
  /* 窄屏时保持输入框可收缩，靠换行排列，比强行拉满更好看也更省空间 */
  .rate-side { flex: 1 1 auto; text-align: center; }
  .rate-note { flex: 1 1 100%; }
}

/* Toast */
.toast-root { position: fixed; right: 18px; bottom: 18px; display: grid; gap: 8px; z-index: 200; }
.toast {
  background: #16202c; color: #fff; padding: 10px 15px; border-radius: 9px;
  font-size: 13px; box-shadow: var(--shadow-lg); max-width: 340px; line-height: 1.55;
  animation: toast-in 0.22s ease-out;
}
.toast.ok { background: #0f8a44; }
.toast.err { background: #c33734; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* 加载 */
.loading { padding: 40px; text-align: center; color: var(--ink-3); }
.spinner {
  width: 22px; height: 22px; border: 2.5px solid var(--line);
  border-top-color: var(--brand); border-radius: 50%;
  animation: spin 0.7s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ================= 响应式 ================= */
@media (max-width: 1000px) {
  .cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 780px) {
  .icon-btn { display: inline-flex; align-items: center; justify-content: center; }
  .sidebar {
    position: fixed; left: 0; top: 0; z-index: 60; height: 100vh;
    transform: translateX(-100%); transition: transform 0.22s ease; box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: none; }
  .scrim.show { display: block; position: fixed; inset: 0; background: rgba(16, 28, 44, 0.4); z-index: 50; }
  .view { padding: 14px; }
  .topbar { padding: 0 12px; }
  .cols-2, .cols-3, .cols-4 { grid-template-columns: minmax(0, 1fr); }
  .stat .value { font-size: 20px; }
  th, td { padding: 9px 10px; }
  .modal-mask { padding: 10px; }
  .modal-body { max-height: 74vh; }
  .dl { grid-template-columns: 84px 1fr; }
}
@media print {
  .sidebar, .topbar, .modal-foot, .no-print { display: none !important; }
  .view { padding: 0; }
  .card { box-shadow: none; border: none; }
  body { background: #fff; }
}
