/* ==========================================================================
   智慧进销存 · 全局样式（移动优先 / 响应式）
   ========================================================================== */

:root {
  --brand: #165DFF;
  --brand-600: #0E42D2;
  --brand-50: #E8F0FF;
  --brand-100: #D6E4FF;

  --success: #00B42A;
  --warning: #FF7D00;
  --danger: #F53F3F;
  --info: #722ED1;

  --up: #F53F3F;    /* 涨 / 收入 —— 中式红 */
  --down: #00B42A;  /* 跌 / 支出 —— 中式绿 */

  --bg: #F5F7FA;
  --bg-elev: #FFFFFF;
  --bg-sunken: #EEF1F6;
  --line: #E5E8EF;
  --line-strong: #D5DAE3;

  --text: #1D2129;
  --text-2: #4E5969;
  --text-3: #86909C;

  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 18px;

  --shadow-sm: 0 1px 2px rgba(29, 33, 41, .06);
  --shadow: 0 4px 14px rgba(29, 33, 41, .08);
  --shadow-lg: 0 12px 32px rgba(29, 33, 41, .14);

  --topbar-h: 56px;
  --sidebar-w: 216px;
  --tabbar-h: 58px;

  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
body { overflow: hidden; }

h1, h2, h3, h4 { margin: 0; font-weight: 600; }
a { color: var(--brand); text-decoration: none; }
button { font-family: inherit; }
.hidden { display: none !important; }

/* ---------- 启动页 ---------- */
.boot {
  position: fixed; inset: 0; z-index: 999;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  background: linear-gradient(160deg, #165DFF, #4080FF 55%, #6AA1FF);
  color: #fff;
}
.boot-logo {
  width: 68px; height: 68px; border-radius: 20px; background: rgba(255,255,255,.18);
  display: grid; place-items: center; font-size: 32px; font-weight: 700;
  backdrop-filter: blur(6px);
}
.boot-text { font-size: 15px; letter-spacing: 3px; opacity: .92; }

/* ---------- 登录 ---------- */
.auth-screen {
  position: fixed; inset: 0; z-index: 900; overflow: auto;
  display: flex; align-items: center; justify-content: center;
  padding: 24px 16px;
  background: linear-gradient(160deg, #EEF4FF 0%, #F5F7FA 60%);
}
.auth-card {
  width: 100%; max-width: 400px; background: var(--bg-elev);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  padding: 28px 24px calc(24px + var(--safe-b));
}
.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.auth-brand h1 { font-size: 19px; }
.auth-brand p { margin: 2px 0 0; font-size: 12px; color: var(--text-3); }
.brand-mark {
  width: 46px; height: 46px; border-radius: 14px; flex: none;
  background: linear-gradient(140deg, var(--brand), #4080FF);
  color: #fff; display: grid; place-items: center; font-size: 22px; font-weight: 700;
  box-shadow: 0 6px 16px rgba(22,93,255,.28);
}
.brand-mark.sm { width: 30px; height: 30px; border-radius: 9px; font-size: 15px; box-shadow: none; }

.auth-tabs { display: flex; gap: 6px; background: var(--bg-sunken); padding: 4px; border-radius: 10px; margin-bottom: 20px; }
.auth-tab {
  flex: 1; border: 0; background: transparent; padding: 8px; border-radius: 7px;
  font-size: 14px; color: var(--text-2); cursor: pointer; transition: .18s;
}
.auth-tab.active { background: #fff; color: var(--brand); font-weight: 600; box-shadow: var(--shadow-sm); }

.auth-error { color: var(--danger); font-size: 12.5px; min-height: 18px; margin: 2px 0 8px; }
.auth-foot { margin-top: 18px; text-align: center; display: flex; flex-direction: column; gap: 4px; }
.auth-note { font-size: 11.5px; color: var(--text-3); }
.link-btn { border: 0; background: none; color: var(--brand); font-size: 13px; cursor: pointer; padding: 4px; }

/* ---------- 表单字段 ---------- */
.field { display: block; margin-bottom: 14px; }
.field-label { display: block; font-size: 12.5px; color: var(--text-2); margin-bottom: 6px; font-weight: 500; }
.field-label .req { color: var(--danger); margin-left: 2px; }
input, select, textarea {
  width: 100%; padding: 10px 12px; font-size: 14px; color: var(--text);
  background: #fff; border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  outline: none; transition: border-color .16s, box-shadow .16s; font-family: inherit;
}
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-50); }
input:disabled, select:disabled { background: var(--bg-sunken); color: var(--text-3); }
textarea { resize: vertical; min-height: 68px; }
input[type=checkbox] { width: auto; }
select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M2 4.5L6 8.5L10 4.5' stroke='%2386909C' stroke-width='1.6' fill='none' stroke-linecap='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; background-size: 12px; padding-right: 30px; }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid transparent; background: #fff; color: var(--text);
  padding: 9px 16px; border-radius: var(--radius-sm); font-size: 14px;
  cursor: pointer; transition: .16s; white-space: nowrap; line-height: 1.3;
}
.btn:hover { border-color: var(--line-strong); }
.btn:active { transform: scale(.98); }
.btn[disabled] { opacity: .5; pointer-events: none; }
.btn-primary { background: var(--brand); color: #fff; box-shadow: 0 2px 8px rgba(22,93,255,.24); }
.btn-primary:hover { background: var(--brand-600); border-color: transparent; }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger-o { background: #FFF1F0; color: var(--danger); border-color: #FFD2D0; }
.btn-warning { background: #FFF4E8; color: var(--warning); border-color: #FFD9AD; }
.btn-warning:hover { background: #FFEAD1; border-color: var(--warning); }
.btn-success { background: var(--success); color: #fff; }
.btn-warn { background: var(--warning); color: #fff; }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-xs { padding: 4px 9px; font-size: 12px; border-radius: 6px; }

.icon-btn {
  border: 0; background: transparent; color: var(--text-2); cursor: pointer;
  width: 36px; height: 36px; border-radius: 9px; display: grid; place-items: center; flex: none;
}
.icon-btn:hover { background: var(--bg-sunken); }
.icon-btn[disabled], .icon-btn:disabled { opacity: .3; pointer-events: none; }

/* ---------- 顶栏 ---------- */
.app { display: flex; flex-direction: column; height: 100dvh; }
.topbar {
  height: calc(var(--topbar-h) + var(--safe-t)); padding-top: var(--safe-t);
  display: flex; align-items: center; gap: 8px; padding-left: 10px; padding-right: 10px;
  background: var(--bg-elev); border-bottom: 1px solid var(--line); flex: none; z-index: 40;
}
.topbar-brand { display: flex; align-items: center; gap: 8px; }
.brand-name { font-size: 15px; font-weight: 700; letter-spacing: .3px; }
.topbar-spacer { flex: 1; }
/* 汉堡菜单按钮：所有宽度都可用 —— 桌面折叠常驻侧栏，窄屏唤出抽屉（见文末「响应式」段） */
#btn-menu { display: grid; }
#btn-menu[aria-expanded="true"] { color: var(--brand); }

.book-switch {
  display: flex; align-items: center; gap: 6px; max-width: 240px;
  border: 1px solid var(--line); background: var(--bg); cursor: pointer;
  padding: 5px 10px; border-radius: 20px; font-size: 13px; color: var(--text-2);
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}
.book-switch span { overflow: hidden; text-overflow: ellipsis; }
.book-switch:hover { border-color: var(--brand); color: var(--brand); }

.sync-chip {
  display: flex; align-items: center; gap: 6px; cursor: pointer;
  padding: 4px 10px; border-radius: 20px; background: var(--bg-sunken);
  font-size: 12px; color: var(--text-2); user-select: none;
}
.sync-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-3); flex: none; }
.sync-dot.on { background: var(--success); }
.sync-dot.syncing { background: var(--warning); animation: pulse 1s infinite; }
.sync-dot.error { background: var(--danger); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .25; } }

.avatar {
  width: 28px; height: 28px; border-radius: 50%; background: var(--brand-100);
  color: var(--brand); display: grid; place-items: center; font-size: 13px; font-weight: 600;
}

/* ---------- 布局 ---------- */
.layout { flex: 1; display: flex; overflow: hidden; }
.sidebar {
  width: var(--sidebar-w); flex: none; background: var(--bg-elev);
  border-right: 1px solid var(--line); padding: 12px 10px; overflow-y: auto;
}
.content { flex: 1; overflow-y: auto; padding: 16px; scroll-behavior: smooth; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 11px; border-radius: 9px;
  color: var(--text-2); cursor: pointer; border: 0; background: transparent;
  font-size: 14px; text-align: left; width: 100%; transition: .15s;
}
.nav-item svg { flex: none; opacity: .8; }
.nav-item:hover { background: var(--bg-sunken); color: var(--text); }
.nav-item.active { background: var(--brand-50); color: var(--brand); font-weight: 600; }
.nav-item.active svg { opacity: 1; }
.nav-group {
  display: flex; align-items: center; justify-content: space-between; width: 100%;
  font-size: 11.5px; color: var(--text-3); padding: 14px 11px 6px; font-weight: 500;
  letter-spacing: .5px; border: 0; background: transparent; cursor: pointer; text-align: left;
}
.nav-group:hover { color: var(--text-2); }
.nav-caret { opacity: .55; transition: transform .18s; }
.nav-caret svg { display: block; }
.nav-group-block.collapsed .nav-caret { transform: rotate(-90deg); }
.nav-group-block.collapsed .nav-item { display: none; }

/* 移动端底部导航 */
.tabbar {
  height: calc(var(--tabbar-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  display: none; background: var(--bg-elev); border-top: 1px solid var(--line); flex: none; z-index: 40;
}
.tabbar .nav-item {
  flex: 1 1 0; width: auto; min-width: 0; flex-direction: column; gap: 2px;
  font-size: 10.5px; padding: 7px 2px 0; border-radius: 0; justify-content: flex-start;
}
.tabbar .nav-item > span:last-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.tabbar .nav-item.active { background: transparent; }
.tabbar .nav-item.active svg { color: var(--brand); }

/* ---------- 页面头 ---------- */
.page-head {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px;
}
.page-title { font-size: 19px; font-weight: 700; }
.page-sub { font-size: 12.5px; color: var(--text-3); }
.page-head .spacer { flex: 1; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- 卡片 ---------- */
.card {
  background: var(--bg-elev); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow-sm); margin-bottom: 14px; overflow: hidden;
}
.card-head {
  display: flex; align-items: center; gap: 10px; padding: 12px 15px;
  border-bottom: 1px solid var(--line); font-weight: 600; font-size: 14.5px;
}
.card-head .spacer { flex: 1; }
.card-body { padding: 15px; }
.card-body.tight { padding: 0; }

/* ---------- 统计卡 ---------- */
.stat-grid {
  display: grid; gap: 12px; margin-bottom: 14px;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
}
.stat {
  background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 15px; box-shadow: var(--shadow-sm); position: relative; overflow: hidden;
}
.stat::after {
  content: ''; position: absolute; right: -22px; top: -22px; width: 62px; height: 62px;
  border-radius: 50%; background: var(--brand-50); opacity: .7;
}
.stat-label { font-size: 12.5px; color: var(--text-3); position: relative; }
.stat-value { font-size: 22px; font-weight: 700; margin-top: 5px; position: relative; font-variant-numeric: tabular-nums; }
.stat-value .unit { font-size: 13px; font-weight: 500; color: var(--text-3); margin-left: 3px; }
.stat-extra { font-size: 12px; color: var(--text-3); margin-top: 4px; position: relative; }
.stat.blue .stat-value { color: var(--brand); }
.stat.green .stat-value { color: var(--success); }
.stat.orange .stat-value { color: var(--warning); }
.stat.purple .stat-value { color: var(--info); }
.stat.red .stat-value { color: var(--danger); }

/* ---------- 快捷入口 ---------- */
.quick-grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); }
.quick {
  display: flex; flex-direction: column; align-items: center; gap: 7px; padding: 14px 6px;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg-elev);
  cursor: pointer; transition: .16s; font-size: 12.5px; color: var(--text-2);
}
.quick:hover { border-color: var(--brand); color: var(--brand); transform: translateY(-1px); box-shadow: var(--shadow); }
.quick .qi {
  width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center;
  background: var(--brand-50); color: var(--brand);
}
.quick.g .qi { background: #E8FFF0; color: var(--success); }
.quick.o .qi { background: #FFF4E8; color: var(--warning); }
.quick.p .qi { background: #F5EDFF; color: var(--info); }
.quick.r .qi { background: #FFF1F0; color: var(--danger); }

/* ---------- 表格 ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; white-space: nowrap; }
table.tbl th, table.tbl td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); }
table.tbl th {
  background: var(--bg-sunken); color: var(--text-2); font-weight: 600; font-size: 12.5px;
  position: sticky; top: 0; z-index: 1;
}
table.tbl tbody tr:hover { background: #FAFBFC; }
table.tbl td.num, table.tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.tbl tfoot td { font-weight: 700; background: #FAFBFC; }
.mono { font-variant-numeric: tabular-nums; }

/* ---------- 列表行 ---------- */
.list { display: flex; flex-direction: column; }
.list-row {
  display: flex; align-items: center; gap: 12px; padding: 12px 15px;
  border-bottom: 1px solid var(--line); cursor: pointer; background: none; border-left: 0; border-right: 0; border-top: 0;
  width: 100%; text-align: left; font-size: 14px; color: var(--text);
}
.list-row:last-child { border-bottom: 0; }
.list-row:hover { background: #FAFBFC; }
.list-main { flex: 1; min-width: 0; }
.list-icon {
  flex: none; width: 34px; height: 34px; border-radius: 9px; display: flex;
  align-items: center; justify-content: center; background: var(--brand-50); color: var(--brand);
}
.list-title { font-weight: 600; display: flex; align-items: center; gap: 6px; }
.list-sub { font-size: 12.5px; color: var(--text-3); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-side { text-align: right; flex: none; }
.list-amount { font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------- 标签 ---------- */
.tag {
  display: inline-flex; align-items: center; padding: 1px 7px; border-radius: 5px;
  font-size: 11.5px; font-weight: 500; line-height: 18px; white-space: nowrap;
}
.tag-blue { background: var(--brand-50); color: var(--brand); }
.tag-green { background: #E8FFF0; color: var(--success); }
.tag-orange { background: #FFF4E8; color: var(--warning); }
.tag-red { background: #FFF1F0; color: var(--danger); }
.tag-purple { background: #F5EDFF; color: var(--info); }
.tag-gray { background: var(--bg-sunken); color: var(--text-2); }

/* ---------- 工具条 ---------- */
.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar .spacer { flex: 1; }
.search {
  position: relative; flex: 1; min-width: 150px; max-width: 320px;
}
.search input { padding-left: 32px; }
.search svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--text-3); pointer-events: none; }

.chips { display: flex; gap: 7px; overflow-x: auto; padding-bottom: 4px; -webkit-overflow-scrolling: touch; }
/* 嵌在工具栏里的 chips（如财务「报表口径」）不再额外留白 */
.toolbar .chips { padding-bottom: 0; }
.chip {
  border: 1px solid var(--line); background: var(--bg-elev); border-radius: 18px;
  padding: 5px 13px; font-size: 13px; color: var(--text-2); cursor: pointer; white-space: nowrap; flex: none;
}
.chip.active { background: var(--brand); border-color: var(--brand); color: #fff; }

/* ---------- 空状态 ---------- */
.empty { text-align: center; padding: 46px 20px; color: var(--text-3); }
.empty-icon { font-size: 40px; opacity: .35; margin-bottom: 10px; }
.empty-title { font-size: 14px; color: var(--text-2); margin-bottom: 4px; }
.empty-sub { font-size: 12.5px; }

/* ---------- 模态 ---------- */
.modal-mask {
  position: fixed; inset: 0; background: rgba(29,33,41,.45); z-index: 1000;
  display: flex; align-items: center; justify-content: center; padding: 16px;
  animation: fade .16s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--bg-elev); border-radius: var(--radius-lg); width: 100%; max-width: 520px;
  max-height: 88dvh; display: flex; flex-direction: column; box-shadow: var(--shadow-lg);
  animation: pop .2s cubic-bezier(.2,.9,.3,1.2);
}
@keyframes pop { from { opacity: 0; transform: translateY(14px) scale(.97); } to { opacity: 1; transform: none; } }
.modal.wide { max-width: 860px; }
.modal-head { display: flex; align-items: center; padding: 15px 18px; border-bottom: 1px solid var(--line); }
.modal-head h3 { font-size: 16px; flex: 1; }
.modal-body { padding: 18px; overflow-y: auto; flex: 1; }
.modal-foot { display: flex; gap: 10px; justify-content: flex-end; padding: 13px 18px calc(13px + var(--safe-b)); border-top: 1px solid var(--line); }

/* 表单栅格 */
.form-grid { display: grid; gap: 13px; grid-template-columns: 1fr 1fr; }
.form-grid .col-2 { grid-column: span 2; }
.switch-row { display: flex; align-items: center; justify-content: space-between; padding: 9px 0; gap: 12px; }
.switch-row .field-label { margin: 0; }
.switch { position: relative; width: 42px; height: 24px; flex: none; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch .track { position: absolute; inset: 0; background: var(--line-strong); border-radius: 20px; transition: .2s; }
.switch .track::after { content: ''; position: absolute; width: 18px; height: 18px; background: #fff; border-radius: 50%; top: 3px; left: 3px; transition: .2s; box-shadow: var(--shadow-sm); }
.switch input:checked + .track { background: var(--brand); }
.switch input:checked + .track::after { transform: translateX(18px); }

/* ---------- 提示 ---------- */
.toast-root { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(74px + var(--safe-b)); z-index: 2000; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; width: max-content; max-width: 92vw; }
.toast {
  background: rgba(29,33,41,.92); color: #fff; padding: 9px 16px; border-radius: 22px;
  font-size: 13.5px; box-shadow: var(--shadow-lg); animation: toastIn .22s ease;
}
.toast.ok { background: rgba(0,180,42,.95); }
.toast.err { background: rgba(245,63,63,.95); }
.toast.warn { background: rgba(212,132,0,.95); }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ---------- 图表（纯 CSS 柱状） ---------- */
.bars { display: flex; align-items: flex-end; gap: 8px; height: 150px; padding-top: 10px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.bar {
  width: 100%; max-width: 34px; border-radius: 6px 6px 2px 2px;
  background: linear-gradient(180deg, #4080FF, var(--brand)); min-height: 3px; transition: height .5s ease;
}
.bar.alt { background: linear-gradient(180deg, #FFB65C, var(--warning)); }
.bar-label { font-size: 11px; color: var(--text-3); }
.bar-wrap { position: relative; width: 100%; display: flex; justify-content: center; height: 100%; align-items: flex-end; }
.bar-val { position: absolute; top: -16px; font-size: 10.5px; color: var(--text-3); font-variant-numeric: tabular-nums; }

.progress { height: 8px; background: var(--bg-sunken); border-radius: 6px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--brand); border-radius: 6px; transition: width .4s; }
.progress.warn > i { background: var(--warning); }
.progress.danger > i { background: var(--danger); }

/* ---------- 详情行 ---------- */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 18px; }
.detail-item .k { font-size: 12px; color: var(--text-3); }
.detail-item .v { font-size: 14px; margin-top: 2px; word-break: break-all; }

/* ---------- 抽屉/底部弹层 ---------- */
.drawer-mask { position: fixed; inset: 0; background: rgba(29,33,41,.45); z-index: 1000; animation: fade .16s; }
.drawer {
  position: fixed; top: 0; bottom: 0; left: 0; width: 82%; max-width: 320px;
  background: var(--bg-elev); z-index: 1001; box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column; animation: slideIn .22s ease;
}
@keyframes slideIn { from { transform: translateX(-100%); } to { transform: none; } }
.drawer-head { padding: 16px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.drawer-body { flex: 1; overflow-y: auto; padding: 12px 10px; }

/* 侧边栏抽屉遮罩（≤1023px 打开侧栏时显示） */
.sidebar-mask {
  display: none; position: fixed; inset: 0;
  background: rgba(29, 33, 41, .45); z-index: 55; animation: fade .16s;
}

/* ---------- 桌面/移动显隐 ---------- */
.mobile-only { display: none; }
@media (min-width: 768px) { .desktop-only { display: block; } .mobile-only { display: none; } }
@media (max-width: 767px) { .desktop-only { display: none; } .mobile-only { display: block; } }

/* ---------- 骨架屏 ---------- */
.skeleton { background: linear-gradient(90deg, #EEF1F6 25%, #F6F8FB 37%, #EEF1F6 63%); background-size: 400% 100%; animation: shimmer 1.3s infinite; border-radius: 6px; }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }

/* ---------- 响应式 ---------- */
/* 桌面：汉堡按钮折叠 / 展开常驻侧栏 */
@media (min-width: 1024px) {
  .app.sidebar-collapsed .sidebar { display: none; }
}

/* 平板与手机：侧栏变为抽屉，由顶栏汉堡按钮唤出 */
@media (max-width: 1023px) {
  #btn-menu { display: grid; }
  .sidebar { position: fixed; top: calc(var(--topbar-h) + var(--safe-t)); bottom: 0; left: 0; z-index: 60; transform: translateX(-100%); transition: transform .24s; box-shadow: var(--shadow-lg); width: 240px; }
  .sidebar.open { transform: none; }
  .sidebar-mask.show { display: block; }
}

@media (max-width: 767px) {
  .tabbar { display: flex; }
  .brand-name { display: none; }
  .book-switch span { max-width: 110px; }
  .sync-label { display: none; }
  .sync-chip { padding: 6px 8px; }
  .content { padding: 12px; padding-bottom: calc(var(--tabbar-h) + 12px); }
  .page-title { font-size: 17px; }
  .stat-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat-value { font-size: 18px; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .col-2 { grid-column: span 1; }
  .modal { max-height: 92dvh; border-radius: var(--radius-lg) var(--radius-lg) 0 0; align-self: flex-end; }
  .modal-mask { align-items: flex-end; padding: 0; }
  .detail-grid { grid-template-columns: 1fr; }
  .quick-grid { grid-template-columns: repeat(4, 1fr); }
  .quick { padding: 12px 4px; font-size: 11.5px; }
  .toast-root { bottom: calc(78px + var(--safe-b)); }
}

@media (min-width: 768px) and (max-width: 1023px) {
  .content { padding: 16px; padding-bottom: 20px; }
  .quick-grid { grid-template-columns: repeat(5, 1fr); }
}

@media (min-width: 1280px) {
  .content { padding: 20px 24px; }
  .content-inner { max-width: 1240px; margin: 0 auto; }
}

/* ---------- 财务：凭证录入表格内的输入控件 ---------- */
table.tbl input, table.tbl select {
  width: 100%; font: inherit; font-size: 12.5px; color: var(--text);
  background: var(--bg-elev); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 5px 7px; outline: none;
}
table.tbl input:focus, table.tbl select:focus { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand-50); }
table.tbl td.num input { text-align: right; font-variant-numeric: tabular-nums; }
table.tbl td.num input::-webkit-outer-spin-button,
table.tbl td.num input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

/* ==========================================================================
   单据 / 报表打印版式（屏幕预览与打印共用同一套 .ps-* 结构）
   抬头内容来自「打印设置」：单位名称、主营产品、联系人、电话、微信、地址…
   ========================================================================== */
#print-root { display: none; }

.ps {
  background: #fff; color: #0b0b0b;
  font-size: 12.5px; line-height: 1.65;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
}
.ps-a4 { width: 210mm; min-height: 297mm; padding: 10mm 5mm; }
.ps-a5 { width: 210mm; min-height: 148mm; padding: 8mm 4mm; }
.ps-receipt { width: 80mm; padding: 3mm 2mm; font-size: 11px; line-height: 1.5; }

/* ---- 抬头 ---- */
.ps-head { text-align: center; padding-bottom: 8px; border-bottom: 2px solid #0b0b0b; }
.ps-left .ps-head { text-align: left; }
.ps-company { font-size: 22px; font-weight: 700; letter-spacing: 2px; line-height: 1.3; }
.ps-company.ps-empty { font-size: 13px; font-weight: 400; color: #999; letter-spacing: 0; }
.ps-subtitle { font-size: 13px; color: #333; margin-top: 2px; }
.ps-scope {
  margin-top: 7px; display: flex; align-items: baseline; gap: 7px;
  justify-content: center; flex-wrap: wrap; font-size: 12.5px;
}
.ps-left .ps-scope { justify-content: flex-start; }
.ps-scope-k {
  flex: none; background: #0b0b0b; color: #fff; border-radius: 3px;
  padding: 1px 7px; font-size: 11px; letter-spacing: 1.5px;
}
.ps-scope-v { font-weight: 600; }
.ps-contact {
  margin-top: 7px; display: flex; flex-wrap: wrap; gap: 3px 16px;
  justify-content: center; font-size: 12px; color: #333;
}
.ps-left .ps-contact { justify-content: flex-start; }
.ps-cb-k { font-style: normal; color: #888; margin-right: 1px; }

/* ---- 单据 / 报表标题 ---- */
.ps-title { text-align: center; font-size: 19px; font-weight: 700; letter-spacing: 6px; margin: 14px 0 12px; }
.ps-left .ps-title { text-align: left; letter-spacing: 4px; }
.ps-report-sub { text-align: center; font-size: 12.5px; color: #555; margin: -8px 0 10px; }

/* ---- 表头信息（两列） ---- */
.ps-meta { border: 1px solid #333; border-bottom: 0; }
.ps-meta-row { display: flex; }
.ps-meta-cell { flex: 1 1 0; min-width: 0; display: flex; gap: 4px; padding: 5px 8px; border-bottom: 1px solid #333; }
.ps-meta-cell + .ps-meta-cell { border-left: 1px solid #333; }
.ps-k { color: #666; flex: none; }
.ps-v { font-weight: 500; word-break: break-all; }
.ps-meta .ps-k::after, .ps-note .ps-k::after, .ps-upper .ps-k::after, .ps-cb-k::after { content: '：'; }

/* ---- 明细表 ---- */
.ps-tbl { width: 100%; border-collapse: collapse; table-layout: fixed; }
.ps-tbl th, .ps-tbl td { border: 1px solid #333; padding: 5px 6px; font-size: 12px; word-break: break-word; vertical-align: top; }
.ps-tbl th { background: #f2f2f2; font-weight: 600; text-align: center; }
.ps-tbl .num { text-align: right; font-variant-numeric: tabular-nums; }
.ps-tbl .idx { text-align: center; }
.ps-tbl .name { word-break: break-word; }
.ps-tbl .mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 11px; }
.ps-tbl tbody tr { height: 26px; }

/* ---- 合计 ---- */
.ps-totals { margin-top: 8px; border: 1px solid #333; }
.ps-total-main, .ps-total-line { display: flex; align-items: center; justify-content: flex-end; gap: 10px; padding: 6px 10px; border-bottom: 1px solid #333; }
.ps-total-main { background: #f7f7f7; }
.ps-total-line:last-child, .ps-total-main:last-child { border-bottom: 0; }
.ps-total-main .ps-v.ps-big { font-size: 15px; font-weight: 700; }
.ps-big { font-size: 14px; font-weight: 700; }
.ps-upper { padding: 6px 10px; display: flex; gap: 8px; align-items: baseline; }
.ps-upper-text { letter-spacing: 1px; font-weight: 600; }

/* ---- 备注 / 签收 / 页脚 ---- */
.ps-note { margin-top: 8px; display: flex; gap: 8px; font-size: 12px; }
.ps-sign { margin-top: 18px; display: flex; flex-wrap: wrap; gap: 8px 22px; font-size: 12.5px; }
.ps-sign-item { min-width: 30%; }
.ps-foot { margin-top: 14px; padding-top: 6px; border-top: 1px dashed #999; text-align: center; font-size: 11.5px; color: #666; }
.ps-left .ps-foot { text-align: left; }

/* ---- 报表套打：克隆界面内容后的收敛排版 ---- */
.ps-report-body .ps-clone { margin-bottom: 10px; }
.ps-report-body .card { box-shadow: none !important; border: 1px solid #ccc !important; border-radius: 0 !important; }
.ps-report-body .card-head { background: #f2f2f2 !important; border-bottom: 1px solid #ccc !important; }
.ps-report-body .card-body { padding: 10px !important; }
.ps-report-body .card-body.tight { padding: 0 !important; overflow: visible !important; }
.ps-report-body .tbl { width: 100%; }
/* 屏幕上的表格是 white-space:nowrap（横向滚动），打印时会溢出纸张，这里放开换行 */
.ps-report-body table.tbl { white-space: normal; table-layout: fixed; }
.ps-report-body .tbl th, .ps-report-body .tbl td {
  border-color: #ccc !important; font-size: 11.5px; padding: 4px 6px;
  white-space: normal !important; word-break: break-word;
}
.ps-report-body .stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.ps-report-body .stat { border: 1px solid #ccc !important; box-shadow: none !important; }
.ps-report-body .bars { break-inside: avoid; }
.ps-report-body .detail-grid { grid-template-columns: repeat(2, 1fr); }

/* ---- 打印设置页的实时预览容器 ---- */
.ps-set-layout { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; }
.ps-set-preview { position: sticky; top: 0; }
.ps-set-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.ps-set-actions .spacer { flex: 1; }
.section-sub {
  font-size: 12.5px; font-weight: 600; color: var(--text-2);
  margin: 14px 0 2px; padding-top: 12px; border-top: 1px dashed var(--line);
}
@media (max-width: 1023px) {
  .ps-set-layout { grid-template-columns: 1fr; }
  .ps-set-preview { position: static; }
}
.ps-preview {
  background: var(--bg-sunken); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px; overflow-x: auto;
}
/* 预览：宽度撑满预览框，但保留与打印一致的页边距（按比例：5mm/210mm ≈ 2.4%，10mm/210mm ≈ 4.8%），
   否则内容会贴死预览框边缘，看起来「打印没有留边距」。 */
.ps-preview .ps { width: 100% !important; min-height: 0 !important; }
.ps-preview .ps-a4, .ps-preview .ps-a5 { padding: 4.8% 2.4% !important; }
.ps-preview .ps-receipt { padding: 3.8% 2.5% !important; }

/* ---------- 打印 ---------- */
@media print {
  /* 只输出 #print-root 里的版式，界面框架一律不外泄 */
  body.printing > *:not(#print-root) { display: none !important; }
  body.printing { overflow: visible !important; height: auto !important; background: #fff !important; }
  #print-root { display: block !important; }
  html, body { height: auto !important; overflow: visible !important; }

  /* @page 已提供页边距，版式本体不再自带宽度与内边距，否则会多出空白页 */
  .ps, .ps-a4, .ps-a5, .ps-receipt { width: auto !important; min-height: 0 !important; padding: 0 !important; }
  .ps-tbl thead { display: table-header-group; }        /* 长表格跨页重复表头 */
  .ps-tbl tr, .ps-report-body .card, .ps-report-body .stat { break-inside: avoid; page-break-inside: avoid; }
  .ps-title { break-after: avoid; page-break-after: avoid; }

  /* 兜底：未走 printNode 的普通打印也不要打出界面框架 */
  .topbar, .sidebar, .tabbar, .page-actions, .toolbar, .sidebar-mask { display: none !important; }
  .content { overflow: visible; padding: 0; }
}
