/* 金仕电商 ERP - light theme */
* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #f5f6f8; --card: #ffffff; --line: #e5e7eb;
  --t1: #1f2329; --t2: #646a73; --t3: #8f959e;
  --blue: #185fa5; --blue-bg: #e6f1fb;
  --teal: #0f6e56; --teal-bg: #e1f5ee;
  --red: #a32d2d; --red-bg: #fcebeb;
  --green: #3b6d11; --green-bg: #eaf3de;
  --amber: #854f0b; --amber-bg: #faeeda;
  --radius: 10px;
}
html, body { height: 100%; }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif; background: var(--bg); color: var(--t1); font-size: 14px; }
.hidden { display: none !important; }
a { color: var(--blue); text-decoration: none; }
button { font-family: inherit; }

/* ---------- 登录 ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(160deg, #eef3f8 0%, #f5f6f8 60%); padding: 24px; }
.login-card { width: 400px; max-width: 96vw; background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 32px 28px; }
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.login-brand h1 { font-size: 20px; font-weight: 600; }
.login-brand .sub { font-size: 12px; color: var(--t2); margin-top: 2px; }
.logo-box { width: 44px; height: 44px; border-radius: 12px; background: var(--blue); color: #fff; font-size: 20px; font-weight: 600; display: flex; align-items: center; justify-content: center; }
.logo-box.sm { width: 30px; height: 30px; font-size: 14px; border-radius: 8px; }
.tab-bar { display: flex; border-bottom: 1px solid var(--line); margin-bottom: 18px; }
.tab-btn { flex: 1; background: none; border: none; padding: 10px 0; font-size: 14px; color: var(--t2); cursor: pointer; border-bottom: 2px solid transparent; }
.tab-btn.active { color: var(--blue); border-bottom-color: var(--blue); font-weight: 600; }
.login-form label { display: block; font-size: 13px; color: var(--t2); margin-bottom: 12px; }
.login-form input { display: block; width: 100%; margin-top: 5px; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px; }
.login-form input:focus { outline: none; border-color: var(--blue); }
.code-row { display: flex; gap: 8px; margin-bottom: 12px; }
.code-row input { flex: 1; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px; }
.form-foot { text-align: right; margin-top: 10px; font-size: 13px; }
.hint { font-size: 12px; color: var(--t3); margin-top: 10px; line-height: 1.5; }
.login-msg { margin-top: 12px; font-size: 13px; min-height: 18px; }
.login-msg.err { color: var(--red); }
.login-msg.ok { color: var(--green); }

/* ---------- 布局 ---------- */
#app-view { display: flex; min-height: 100vh; }
.sidebar { width: 200px; background: #ffffff; border-right: 1px solid var(--line); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.side-brand { display: flex; align-items: center; gap: 8px; padding: 16px 14px; font-weight: 600; font-size: 15px; border-bottom: 1px solid var(--line); }
#side-nav { flex: 1; padding: 10px 8px; overflow-y: auto; }
.nav-item { display: flex; align-items: center; gap: 8px; padding: 9px 12px; border-radius: 8px; color: var(--t2); cursor: pointer; margin-bottom: 2px; font-size: 14px; }
.nav-item:hover { background: var(--bg); color: var(--t1); }
.nav-item.active { background: var(--blue-bg); color: var(--blue); font-weight: 600; }
.nav-item .ico { width: 18px; text-align: center; font-style: normal; }
.side-user { border-top: 1px solid var(--line); padding: 12px 14px; }
.u-name { font-weight: 600; font-size: 14px; }
.u-role { font-size: 12px; color: var(--t2); margin: 2px 0 8px; }
.sm-btn { width: 100%; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 14px 22px; background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.topbar h2 { font-size: 17px; font-weight: 600; }
.page-body { padding: 18px 22px 40px; }

/* ---------- 通用组件 ---------- */
.btn { border: 1px solid var(--line); background: #fff; color: var(--t1); border-radius: 8px; padding: 7px 14px; font-size: 13px; cursor: pointer; }
.btn:hover { border-color: var(--blue); color: var(--blue); }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary:hover { opacity: .9; color: #fff; }
.btn.danger { color: var(--red); border-color: #f0bcbc; }
.btn.danger:hover { background: var(--red-bg); }
.btn.ghost { background: var(--bg); }
.btn.block { width: 100%; padding: 10px; font-size: 15px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.mini { padding: 3px 8px; font-size: 12px; border-radius: 6px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.card h3 { font-size: 14px; font-weight: 600; margin-bottom: 12px; }
.grid-kpi { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.kpi .k-label { font-size: 12px; color: var(--t2); }
.kpi .k-val { font-size: 22px; font-weight: 600; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .k-sub { font-size: 12px; margin-top: 3px; color: var(--t3); }
.k-up { color: var(--red); } .k-down { color: var(--green); }

.filter-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.filter-bar select, .filter-bar input { padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 13px; background: #fff; }
.btn.xs { padding: 4px 10px; font-size: 12px; border-radius: 6px; }
.date-shortcuts { display: inline-flex; gap: 4px; flex-wrap: wrap; align-items: center; margin-left: 4px; }
.date-shortcuts .btn { background: #f6f8fc; color: var(--t2); border: 1px solid var(--line); padding: 4px 10px; border-radius: 6px; cursor: pointer; font-size: 12px; }
.date-shortcuts .btn:hover { background: var(--brand); color: #fff; border-color: var(--brand); }
.filter-bar input[type="date"], .filter-bar input[type="text"], .filter-bar input[type="search"] { width: 140px; }

.table-wrap { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 640px; }
th { background: #fafbfc; color: var(--t2); font-weight: 500; text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 9px 12px; border-bottom: 1px solid #f0f1f3; white-space: nowrap; }
tr:hover td { background: #fafbfc; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
th.num { text-align: right; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 12px; }
.b-gray { background: #f1f2f4; color: var(--t2); }
.b-blue { background: var(--blue-bg); color: var(--blue); }
.b-green { background: var(--green-bg); color: var(--green); }
.b-red { background: var(--red-bg); color: var(--red); }
.b-amber { background: var(--amber-bg); color: var(--amber); }
.b-teal { background: var(--teal-bg); color: var(--teal); }

.pager { display: flex; align-items: center; justify-content: flex-end; gap: 10px; padding: 12px 4px; font-size: 13px; color: var(--t2); }

.empty { text-align: center; color: var(--t3); padding: 40px 0; font-size: 13px; }

/* 图表 */
.chart { width: 100%; height: 300px; }
.chart-tall { width: 100%; height: 360px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-2 .card { margin-bottom: 0; }
@media (max-width: 1000px) { .grid-2 { grid-template-columns: 1fr; } .sidebar { width: 64px; } .side-brand span, .u-name, .u-role, .nav-item span { display: none; } }

/* 弹窗 */
.modal-mask { position: fixed; inset: 0; background: rgba(31,35,41,.4); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal { background: #fff; border-radius: 14px; width: 460px; max-width: 94vw; max-height: 86vh; overflow: auto; padding: 20px 22px; }
.modal.wide { width: 880px; max-height: 90vh; padding: 18px 20px; }
.modal h3 { font-size: 15px; margin-bottom: 14px; }
.modal .m-body label { display: block; font-size: 13px; color: var(--t2); margin-bottom: 10px; }
.modal .m-body input, .modal .m-body select, .modal .m-body textarea { display: block; width: 100%; margin-top: 4px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 13px; font-family: inherit; }
.modal .m-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }
/* 财务订单明细模块专用：分区块+实时算 */
.modal .m-fieldset { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; margin-bottom: 12px; }
.modal .m-fieldset legend { padding: 0 6px; font-size: 13px; color: var(--blue); font-weight: bold; }
.modal .m-fieldset .m-grid { display: grid; gap: 6px 10px; }
.modal .m-fieldset .m-grid.c2 { grid-template-columns: 1fr 1fr; }
.modal .m-fieldset .m-grid.c3 { grid-template-columns: 1fr 1fr 1fr; }
.modal .m-fieldset .m-grid.c4 { grid-template-columns: 1fr 1fr 1fr 1fr; }
.modal .m-fieldset label { display: flex; align-items: center; gap: 6px; margin-bottom: 0; font-size: 12px; }
.modal .m-fieldset label > input, .modal .m-fieldset label > select, .modal .m-fieldset label > textarea { flex: 1; margin-top: 0; font-size: 12px; padding: 6px 8px; }
.modal .m-fieldset label > .lbl { flex: 0 0 auto; min-width: 60px; color: var(--t2); }
.modal .m-fieldset .m-yes { flex: 0 0 auto; font-size: 11px; color: var(--t3); display: inline-flex; align-items: center; gap: 3px; min-width: 80px; }
.modal .m-fieldset .m-yes input[type=checkbox] { width: 14px; height: 14px; margin: 0; }
.modal .m-calc { background: #fff7e6; border: 1px dashed #f0c060; border-radius: 8px; padding: 10px 14px; font-size: 13px; display: flex; gap: 18px; flex-wrap: wrap; }
.modal .m-calc b { color: var(--blue); }

/* 财务订单明细：成本行（单价 × 数量 = 金额） */
.modal .m-fieldset .m-cost-row { display: flex; align-items: center; gap: 6px; margin-bottom: 0; flex-wrap: wrap; }
.modal .m-fieldset .m-cost-row.full { grid-column: 1 / -1; }
.modal .m-fieldset .m-cost-row .lbl { flex: 0 0 auto; min-width: 84px; color: var(--t2); }
.modal .m-fieldset .m-cost-row input[type="number"] { width: 78px; flex: 0 0 auto; }
.modal .m-fieldset .m-cost-row .m-op { color: var(--t3); font-size: 12px; }
.modal .m-fieldset .m-cost-row .m-amt { min-width: 72px; text-align: right; font-weight: bold; color: var(--blue); font-size: 13px; }
.modal .m-fieldset .m-cost-row .m-yes { margin-left: auto; }

/* toast */
#toast { position: fixed; top: 18px; left: 50%; transform: translateX(-50%); z-index: 99; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast-item { background: #1f2329; color: #fff; padding: 9px 18px; border-radius: 8px; font-size: 13px; opacity: 0; transition: opacity .2s; }
.toast-item.show { opacity: .95; }
.toast-item.err { background: #a32d2d; }

/* ---------- 启动加载层（避免刷新看到登录页闪烁） ---------- */
.splash { position: fixed; inset: 0; background: #ffffff; display: flex; flex-direction: column; align-items: center; justify-content: center; z-index: 9999; }
.splash.fade { opacity: 0; transition: opacity .25s; pointer-events: none; }
.spinner { width: 38px; height: 38px; border: 3px solid #e5e7eb; border-top-color: #185fa5; border-radius: 50%; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.task-item { display: flex; align-items: center; gap: 10px; padding: 10px 4px; border-bottom: 1px solid #f0f1f3; font-size: 13px; }
.task-item:last-child { border-bottom: none; }
.task-item .t-title { flex: 1; }
.task-item.done .t-title { color: var(--t3); text-decoration: line-through; }

/* ---------- 手机端（PWA）适配 ---------- */
@media (max-width: 760px) {
  /* 布局：左侧栏改为顶部横向导航条（APP 手感） */
  #app-view { flex-direction: column; }
  .sidebar {
    width: 100%; height: auto; position: sticky; top: 0; z-index: 20;
    flex-direction: row; align-items: center;
    border-right: none; border-bottom: 1px solid var(--line);
    background: #ffffff;
  }
  .side-brand { display: none; }
  #side-nav {
    display: flex; flex-direction: row; overflow-x: auto; overflow-y: hidden;
    flex: 1; padding: 6px; gap: 2px;
    -webkit-overflow-scrolling: touch; scrollbar-width: none;
  }
  #side-nav::-webkit-scrollbar { display: none; }
  .nav-item {
    white-space: nowrap; padding: 9px 13px; margin: 0; font-size: 14px; border-radius: 8px;
  }
  .nav-item span { display: inline; } /* 覆盖 <1000px 的隐藏规则，菜单文字必须可见 */
  .side-user { border-top: none; padding: 6px; border-left: 1px solid var(--line); flex-shrink: 0; }
  .side-user .u-name, .side-user .u-role { display: none; }
  .sm-btn { width: auto; white-space: nowrap; padding: 8px 10px; font-size: 13px; }
  .main { min-width: 0; }
  .topbar { position: static; padding: 10px 14px; }
  .topbar h2 { font-size: 16px; }

  .page-body { padding: 12px 12px 90px; }
  .card { padding: 12px; }
  .kpi .k-val { font-size: 18px; }
  .grid-kpi { gap: 8px; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }
  .filter-bar { gap: 6px; }
  .filter-bar input[type="date"], .filter-bar input[type="text"], .filter-bar input[type="search"] { width: 120px; }
  /* 触屏：按钮和行更大更好点 */
  .btn { padding: 9px 14px; }
  .btn.mini { padding: 6px 10px; font-size: 13px; }
  td, th { padding: 10px 10px; }
  .modal { width: 94vw; padding: 16px; }
  /* Toast 全宽 + 刘海屏安全区 */
  #toast { top: calc(12px + env(safe-area-inset-top)); left: 12px; right: 12px; transform: none; align-items: stretch; }
  .toast-item { text-align: center; }
}
