/* 锂电池国际贸易管理系统 · 界面层样式
   纯本地应用，无任何外部字体/CDN 依赖 */

:root {
  --bg: #f2f4f8;
  --panel: #ffffff;
  --ink: #1e2532;
  --ink-2: #46506b;
  --muted: #7d879e;
  --line: #e4e8f0;
  --line-2: #eef1f7;
  --brand: #1f3864;
  --brand-2: #2f5597;
  --brand-3: #4472c4;
  --brand-soft: #e8eefb;
  --ok: #12805c;
  --ok-bg: #e3f6ee;
  --warn: #b06a00;
  --warn-bg: #fdf1dd;
  --bad: #c0341d;
  --bad-bg: #fde9e5;
  --calc-bg: #fbfaf5;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(23, 38, 71, .06), 0 6px 20px rgba(23, 38, 71, .05);
  --mono: "Cascadia Mono", "Consolas", "SFMono-Regular", "Menlo", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 "Microsoft YaHei UI", "Microsoft YaHei", "PingFang SC",
        "Hiragino Sans GB", "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8;
      stroke-linecap: round; stroke-linejoin: round; flex: none; }

button, input, select, textarea { font: inherit; color: inherit; }

/* ------------------------------------------------------------------ 布局 */
.app { display: flex; height: 100vh; overflow: hidden; }

.sidebar {
  width: 232px; flex: none; display: flex; flex-direction: column;
  background: linear-gradient(180deg, #1b3159 0%, #152744 100%);
  color: #cdd8ef;
}
.brand { display: flex; gap: 10px; align-items: center; padding: 16px 16px 14px; }
.brand-mark { width: 30px; height: 30px; stroke: #8fb4f0; stroke-width: 1.4; }
.brand-text b { display: block; color: #fff; font-size: 14.5px; letter-spacing: .3px; }
.brand-text span { font-size: 11px; color: #7f92b8; }

.nav { flex: 1; overflow: auto; padding: 4px 10px 10px; }
.nav-group { font-size: 10.5px; letter-spacing: 1.2px; color: #6a7ea6;
             padding: 14px 8px 6px; text-transform: uppercase; }
.nav a {
  display: flex; align-items: center; gap: 9px; padding: 8px 10px; margin: 1px 0;
  border-radius: 7px; color: #cdd8ef; text-decoration: none; font-size: 13.2px;
}
.nav a svg { stroke: #8ba4d0; }
.nav a:hover { background: rgba(255, 255, 255, .07); color: #fff; }
.nav a.active { background: rgba(68, 114, 196, .28); color: #fff; box-shadow: inset 2px 0 0 #7ea6f0; }
.nav a.active svg { stroke: #cfe0ff; }

.side-foot { padding: 12px 14px; border-top: 1px solid rgba(255, 255, 255, .09); }
.side-stat { font-size: 11.5px; color: #9fb2d6; margin-bottom: 6px; word-break: break-all; }
.side-hint { font-size: 10.5px; color: #63769c; line-height: 1.6; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  height: 58px; flex: none; display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.crumb h1 { margin: 0; font-size: 17px; font-weight: 600; }
.crumb p { margin: 1px 0 0; font-size: 12px; color: var(--muted); }
.top-actions { display: flex; gap: 8px; }

.view { flex: 1; overflow: auto; padding: 18px 20px 40px; scroll-behavior: smooth; }

/* ------------------------------------------------------------------ 通用件 */
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px;
  border: 1px solid var(--line); border-radius: 7px; background: #fff; cursor: pointer;
  font-size: 13px; color: var(--ink-2); transition: .12s;
}
.btn:hover { border-color: #c3cee0; background: #f7f9fd; color: var(--ink); }
.btn.primary { background: var(--brand-2); border-color: var(--brand-2); color: #fff; }
.btn.primary:hover { background: var(--brand); border-color: var(--brand); }
.btn.ghost { background: #fff; }
.btn.danger { color: var(--bad); border-color: #f0cdc5; background: #fff; }
.btn.danger:hover { background: var(--bad-bg); }
.btn.sm { padding: 3px 8px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.icon { padding: 5px 7px; }

.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 16px; }
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; border-bottom: 1px solid var(--line-2);
}
.card-head h3 { margin: 0; font-size: 14px; font-weight: 600; }
.card-head p { margin: 2px 0 0; font-size: 11.5px; color: var(--muted); }
.card-body { padding: 14px 16px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
@media (max-width: 1180px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

/* ------------------------------------------------------------------ KPI */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(184px, 1fr)); gap: 12px; }
.kpi {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; box-shadow: var(--shadow); position: relative; overflow: hidden;
}
.kpi::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
               background: var(--brand-3); opacity: .55; }
.kpi.is-pct::before { background: var(--ok); }
.kpi label { display: block; font-size: 11.5px; color: var(--muted); margin-bottom: 5px; }
.kpi .val { font-size: 20px; font-weight: 600; letter-spacing: -.2px; font-variant-numeric: tabular-nums; }
.kpi .unit { font-size: 11.5px; color: var(--muted); margin-left: 3px; font-weight: 400; }
.kpi .note { font-size: 10.5px; color: #97a1b6; margin-top: 5px; line-height: 1.4; }
.kpi .val.neg { color: var(--bad); }
.kpi .val.pos { color: var(--ok); }

/* ------------------------------------------------------------------ 表格 */
.table-wrap { overflow: auto; max-height: calc(100vh - 210px); border-top: 1px solid var(--line-2); }
table.data { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 12.8px; }
table.data th, table.data td {
  padding: 7px 10px; border-bottom: 1px solid var(--line-2); text-align: left;
  white-space: nowrap; vertical-align: middle;
}
table.data thead th {
  position: sticky; top: 0; z-index: 3; background: #f6f8fc; color: var(--ink-2);
  font-weight: 600; font-size: 12px; box-shadow: inset 0 -1px 0 var(--line);
  cursor: pointer; user-select: none;
}
table.data thead th .sort { opacity: .28; margin-left: 3px; width: 12px; height: 12px;
                            vertical-align: -1px; }
table.data thead th.sorted .sort { opacity: 1; stroke: var(--brand-2); }
table.data th.col-idx, table.data td.col-idx {
  position: sticky; left: 0; z-index: 2; background: #fbfcfe; text-align: right;
  color: var(--muted); font-family: var(--mono); font-size: 11.5px; width: 44px;
}
table.data th.col-idx { z-index: 4; background: #f6f8fc; }
table.data th.col-act, table.data td.col-act {
  position: sticky; right: 0; z-index: 2; background: #fbfcfe; text-align: center; width: 96px;
}
table.data th.col-act { z-index: 4; background: #f6f8fc; }
table.data tbody tr:hover td { background: #f4f7fe; }
table.data tbody tr:hover td.col-idx, table.data tbody tr:hover td.col-act { background: #eef3fc; }
table.data td.num { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }
table.data td.drv { background: var(--calc-bg); color: #5c5a4a; }
table.data td.editable { cursor: text; }
table.data td.editable:hover { box-shadow: inset 0 0 0 1.5px #bfd2f2; }
table.data td .neg { color: var(--bad); }
table.data td.editing { padding: 0; }
table.data td input.cell, table.data td select.cell {
  width: 100%; border: 1px solid var(--brand-3); border-radius: 3px; padding: 6px 8px;
  outline: none; background: #fff; font: inherit;
}
table.data tfoot td {
  position: sticky; bottom: 0; background: #f0f3fa; font-weight: 600; z-index: 3;
  box-shadow: inset 0 1px 0 var(--line);
}

.tag { display: inline-block; padding: 1px 7px; border-radius: 20px; font-size: 11px;
       background: #eef2f8; color: var(--ink-2); }
.tag.ok { background: var(--ok-bg); color: var(--ok); }
.tag.warn { background: var(--warn-bg); color: var(--warn); }
.tag.bad { background: var(--bad-bg); color: var(--bad); }
.tag.calc { background: #f4f0e2; color: #8a7333; }

/* ------------------------------------------------------------------ 工具栏 */
.toolbar {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  padding: 11px 14px; border-bottom: 1px solid var(--line-2); background: #fcfdff;
}
.toolbar .search { position: relative; }
.toolbar .search svg { position: absolute; left: 8px; top: 7px; stroke: var(--muted); width: 14px; height: 14px; }
.toolbar input[type=text], .toolbar input[type=date], .toolbar select, .field select, .field input {
  border: 1px solid var(--line); border-radius: 6px; padding: 5px 9px; background: #fff;
  outline: none; font-size: 12.8px;
}
.toolbar input[type=text] { padding-left: 27px; width: 200px; }
.toolbar select { max-width: 160px; }
.toolbar .spacer { flex: 1; }
.toolbar .hint { font-size: 11.5px; color: var(--muted); }

.pager {
  display: flex; align-items: center; gap: 10px; padding: 9px 14px;
  border-top: 1px solid var(--line-2); font-size: 12.5px; color: var(--ink-2);
  background: #fcfdff;
}
.pager .pages { display: flex; gap: 4px; align-items: center; }
.pager select { border: 1px solid var(--line); border-radius: 6px; padding: 3px 6px; background: #fff; }
.pager input { width: 52px; text-align: center; border: 1px solid var(--line);
               border-radius: 6px; padding: 3px 4px; }

.empty { padding: 46px 20px; text-align: center; color: var(--muted); font-size: 13px; }
.empty b { display: block; color: var(--ink-2); font-size: 14px; margin-bottom: 6px; }

/* ------------------------------------------------------------------ 图表 */
.chart-row { display: flex; gap: 16px; flex-wrap: wrap; align-items: flex-start; }
.chart-box { flex: 1; min-width: 300px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 10px; font-size: 12px; }
.legend i { width: 9px; height: 9px; border-radius: 2px; display: inline-block; margin-right: 5px; }
.legend span { color: var(--ink-2); }
.legend b { color: var(--ink); font-variant-numeric: tabular-nums; margin-left: 4px; }

.alerts { display: flex; flex-direction: column; gap: 8px; }

/* 横向条形图 */
.bars { display: flex; flex-direction: column; gap: 6px; }
.bar-row { display: flex; align-items: center; gap: 10px; font-size: 12.3px; }
.bar-label { width: 96px; flex: none; text-align: right; color: var(--ink-2);
             overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { flex: 1; height: 15px; background: #f0f3f8; border-radius: 3px; position: relative; }
.bar-track[data-axis]::before { content: ""; position: absolute; left: 50%; top: -2px; bottom: -2px;
                                width: 1px; background: #c9d5ea; }
.bar-track i { position: absolute; top: 2px; bottom: 2px; border-radius: 2px; min-width: 2px; }
.bar-val { width: 96px; flex: none; text-align: right; font-family: var(--mono);
           font-variant-numeric: tabular-nums; font-size: 11.8px; }
.bar-val.neg { color: var(--bad); }

/* 月度柱状图 */
.cols-body { display: flex; align-items: flex-end; gap: 6px; height: 168px; padding-top: 6px;
             border-bottom: 1px solid var(--line); }
.col-group { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; min-width: 0; }
.col-pair { flex: 1; width: 100%; display: flex; align-items: flex-end; gap: 2px; }
.col-pair i { flex: 1; border-radius: 2px 2px 0 0; min-height: 1px; }
.col-pair .c1 { background: #4472c4; }
.col-pair .c2 { background: #70ad47; }
.col-x { font-size: 10.5px; color: var(--muted); padding: 4px 0 2px; }
.alert-item { display: flex; gap: 10px; align-items: flex-start; padding: 9px 12px;
              border-radius: 8px; border: 1px solid var(--line); background: #fcfdff; }
.alert-item.bad { background: var(--bad-bg); border-color: #f3cfc7; }
.alert-item.warn { background: var(--warn-bg); border-color: #f2ddb9; }
.alert-item svg { margin-top: 2px; }
.alert-item.bad svg { stroke: var(--bad); }
.alert-item.warn svg { stroke: var(--warn); }
.alert-item .t { flex: 1; font-size: 12.8px; }
.alert-item .t b { display: block; font-size: 11.5px; letter-spacing: .3px; margin-bottom: 1px; }

/* ------------------------------------------------------------------ 弹窗 */
.modal { position: fixed; inset: 0; z-index: 60; display: flex; align-items: center;
         justify-content: center; }
.modal.hidden, .login.hidden { display: none; }
.modal-mask { position: absolute; inset: 0; background: rgba(20, 30, 50, .45); backdrop-filter: blur(1px); }
.modal-panel {
  position: relative; width: min(880px, 92vw); max-height: 88vh; overflow: auto;
  background: #fff; border-radius: 12px; box-shadow: 0 20px 60px rgba(15, 25, 45, .28);
  animation: pop .16s ease-out;
}
@keyframes pop { from { transform: translateY(8px) scale(.99); opacity: .6; } }
.modal-head { display: flex; align-items: center; justify-content: space-between;
              padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; font-size: 15px; }
.modal-head span { font-size: 11.5px; color: var(--muted); }
.modal-body { padding: 16px 18px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px;
              border-top: 1px solid var(--line); background: #fbfcfe; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px 14px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field > label { font-size: 11.5px; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.field input, .field select, .field textarea {
  border: 1px solid var(--line); border-radius: 6px; padding: 6px 9px; background: #fff; outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--brand-3);
  box-shadow: 0 0 0 3px rgba(68, 114, 196, .12); }
.field textarea { resize: vertical; min-height: 56px; }
.field .wide { grid-column: 1 / -1; }
.field .lbl-calc { font-size: 10px; padding: 1px 5px; border-radius: 3px; background: #f4f0e2; color: #8a7333; }
.readonly-val { padding: 5px 0; font-family: var(--mono); font-size: 12.5px; color: var(--ink-2); }

/* ---------------------------------------------------------- 下拉候选控件 */
.dv-wrap { position: relative; width: 100%; }
.dv-wrap > input { width: 100%; padding-right: 28px; }
table.data td .dv-wrap > input.cell, .field .dv-wrap > input { padding-right: 28px; }
.dv-arrow {
  position: absolute; right: 1px; top: 1px; bottom: 1px; width: 24px;
  border: 0; border-left: 1px solid var(--line); border-radius: 0 5px 5px 0;
  background: var(--brand-soft); color: var(--brand-2); cursor: pointer;
  font-size: 12px; line-height: 1; padding: 0;
}
.dv-arrow:hover { background: #d9e5fb; }
.dv-menu {
  position: absolute; top: calc(100% + 2px); left: 0; right: 0; z-index: 60;
  max-height: 230px; overflow-y: auto; background: #fff;
  border: 1px solid var(--line); border-radius: 6px; box-shadow: var(--shadow);
}
.dv-menu.hidden { display: none; }
.dv-opt { padding: 6px 10px; font-size: 12.8px; cursor: pointer;
         white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dv-opt:hover { background: var(--brand-soft); color: var(--brand); }
.dv-empty-hint { font-size: 11px; color: var(--warn); margin-top: 1px; }
.dv-empty-hint a { color: var(--brand-2); text-decoration: underline; }

/* ------------------------------------------------------------------ 提示 */
.toast-wrap { position: fixed; top: 14px; left: 50%; transform: translateX(-50%);
              z-index: 90; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast {
  padding: 9px 16px; border-radius: 8px; background: #1f2937; color: #fff; font-size: 13px;
  box-shadow: 0 8px 26px rgba(15, 25, 45, .22); animation: fade .18s ease-out;
}
.toast.ok { background: #0f6b4e; }
.toast.bad { background: #a5301a; }
@keyframes fade { from { opacity: 0; transform: translateY(-6px); } }

/* ------------------------------------------------------------------ 配置 / Excel 中心 */
.cfg-list { border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.cfg-list h4 { margin: 0; padding: 9px 12px; background: #f6f8fc; font-size: 12.5px;
               border-bottom: 1px solid var(--line-2); display: flex; align-items: center; gap: 8px; }
.cfg-list h4 .n { color: var(--muted); font-weight: 400; font-size: 11.5px; }
.cfg-items { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 12px; }
.cfg-item { display: inline-flex; align-items: center; gap: 5px; padding: 3px 5px 3px 9px;
            border: 1px solid var(--line); border-radius: 16px; background: #fff; font-size: 12.3px; }
.cfg-item .x { border: none; background: none; cursor: pointer; color: var(--muted);
               line-height: 1; padding: 2px 4px; border-radius: 10px; }
.cfg-item .x:hover { background: var(--bad-bg); color: var(--bad); }
.cfg-add { display: flex; gap: 6px; padding: 9px 12px; border-top: 1px solid var(--line-2); background: #fcfdff; }
.cfg-add input { flex: 1; min-width: 90px; }

.file-list { display: flex; flex-direction: column; }
.file-row { display: flex; align-items: center; gap: 12px; padding: 9px 14px;
            border-bottom: 1px solid var(--line-2); font-size: 12.8px; }
.file-row:hover { background: #f7f9fd; }
.file-row .nm { flex: 1; font-family: var(--mono); font-size: 12px; word-break: break-all; }
.file-row .sz, .file-row .mt { color: var(--muted); font-size: 11.5px; width: 96px; }

.drop { border: 2px dashed #c9d5ea; border-radius: 10px; padding: 26px; text-align: center;
        color: var(--muted); background: #fbfcff; transition: .15s; }
.drop:hover, .drop.over { border-color: var(--brand-3); background: #f2f6fe; color: var(--brand-2); }
.drop b { display: block; color: var(--ink-2); font-size: 14px; margin-bottom: 4px; }

.login { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center;
         justify-content: center; background: linear-gradient(160deg, #1b3159, #0f1e36); }
.login-card { background: #fff; padding: 30px 32px; border-radius: 12px; width: 320px;
              box-shadow: 0 24px 60px rgba(0, 0, 0, .3); }
.login-card h2 { margin: 0 0 4px; font-size: 19px; }
.login-card p { margin: 0 0 18px; font-size: 12.5px; color: var(--muted); }
.login-card input { width: 100%; margin-bottom: 10px; padding: 9px 11px; border: 1px solid var(--line);
                    border-radius: 7px; outline: none; }
.login-card input:focus { border-color: var(--brand-3); }
.login-card button { width: 100%; justify-content: center; margin-top: 4px; }
.login-card .err { display: block; margin-top: 10px; color: var(--bad); font-size: 12.3px; min-height: 16px; }

.status-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.status-item { padding: 12px 14px; border: 1px solid var(--line); border-radius: 9px; background: #fff; }
.status-item label { display: block; font-size: 11.5px; color: var(--muted); margin-bottom: 4px; }
.status-item b { font-size: 15px; font-variant-numeric: tabular-nums; }
.status-item code { font-family: var(--mono); font-size: 11.5px; color: var(--ink-2); word-break: break-all; }
