:root {
  --bg: #f4f6fb;
  --card: #fff;
  --ink: #1f2733;
  --muted: #6b7686;
  --line: #e4e8f0;
  --brand: #1d4ed8;
  --brand-dark: #1e40af;
  --ok: #16a34a;
  --warn: #d97706;
  --bad: #dc2626;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(16,24,40,.08);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  background: var(--bg); color: var(--ink); font-size: 14px; line-height: 1.55;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 218px; flex: 0 0 218px; background: #14213d; color: #cbd5e1;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.sidebar .logo { padding: 18px 16px 14px; border-bottom: 1px solid rgba(255,255,255,.08); }
.sidebar .logo b { color: #fff; font-size: 17px; display: block; }
.sidebar .logo span { font-size: 12px; color: #8fa3c8; }
.sidebar nav { padding: 10px 8px; flex: 1; overflow-y: auto; }
.sidebar nav a {
  display: flex; align-items: center; gap: 9px; padding: 9px 12px; border-radius: 8px;
  color: #cbd5e1; font-size: 14px; margin-bottom: 2px;
}
.sidebar nav a:hover { background: rgba(255,255,255,.08); color: #fff; text-decoration: none; }
.sidebar nav a.active { background: var(--brand); color: #fff; font-weight: 600; }
.sidebar-mobile-user, .sidebar-mobile-search { display: none; }
.sidebar-mobile-actions { display: none; }
.sidebar .ver { padding: 12px 16px; font-size: 12px; color: #6b7fa8; border-top: 1px solid rgba(255,255,255,.08); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  background: var(--card); border-bottom: 1px solid var(--line); padding: 10px 22px;
  display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 5;
}
.topbar .crumbs { color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 8px; min-width: 0; }
.search-bar { flex: 1; max-width: 300px; margin: 0 12px; }
.search-bar input { width: 100%; padding: 7px 12px; border: 1px solid var(--line); border-radius: 8px; font-size: 13px; background: #f8fafc; }
.burger { display: none; background: none; border: 1px solid var(--line); border-radius: 8px; font-size: 17px; line-height: 1; padding: 5px 9px; cursor: pointer; color: var(--ink); }
.mask { display: none; position: fixed; inset: 0; background: rgba(15,23,42,.45); z-index: 30; }
.role-modal-mask { display: none; position: fixed; inset: 0; background: rgba(15,23,42,.5); z-index: 60; align-items: center; justify-content: center; padding: 16px; }
.role-modal-mask.show { display: flex; }
.role-modal { background: #fff; border-radius: 14px; padding: 20px 22px; width: 360px; max-width: 92vw; box-shadow: 0 20px 60px rgba(0,0,0,.28); }
.role-modal-head { display: flex; align-items: center; justify-content: space-between; font-size: 16px; margin-bottom: 4px; }
.role-modal-head .x { border: none; background: none; font-size: 18px; cursor: pointer; color: var(--muted); line-height: 1; padding: 2px 6px; }
.role-options { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.role-options label { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; transition: all .15s; }
.role-options label:hover { border-color: var(--brand); background: #f8faff; }
.role-options label.on { border-color: var(--brand); background: #eef4ff; }
.role-options input { width: auto; margin: 0; }
.role-options span { display: flex; flex-direction: column; }
.role-options b { font-size: 14px; color: var(--ink); }
.role-options i { font-size: 12px; color: var(--muted); font-style: normal; }
.sidebar.open { transform: translateX(0); }
.topbar .user { display: flex; align-items: center; gap: 12px; font-size: 13px; color: var(--muted); }
.topbar .user b { color: var(--ink); }
.mobile-org-switch { display: none; }
.content { padding: 20px 22px 40px; max-width: 1280px; width: 100%; }

.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; gap: 12px; flex-wrap: wrap; }
.page-head h1 { font-size: 20px; margin: 0; }
.page-head .sub { color: var(--muted); font-size: 13px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; margin-bottom: 16px; }
.card h3 { margin: 0 0 12px; font-size: 15px; }
.card .hint { color: var(--muted); font-size: 12px; margin-top: 6px; }

.grid { display: grid; gap: 14px; }
.grid.g4 { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.grid.g3 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }

.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; }
.stat .label { color: var(--muted); font-size: 12px; }
.stat .num { font-size: 24px; font-weight: 700; margin-top: 4px; }
.stat .num.small { font-size: 18px; }
.stat .sub2 { color: var(--muted); font-size: 12px; margin-top: 2px; }

table.tbl { width: 100%; border-collapse: collapse; background: var(--card); }
.tbl th, .tbl td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.tbl th { background: #f8fafc; font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; }
.tbl tr:hover td { background: #f8fafc; }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl .actions { white-space: nowrap; }

/* 客户/供应商列表：表头随表格内部滚动固定在顶部 */
.partner-table-card {
  overflow: visible !important;
  position: relative;
}
.tbl.sticky-head { border-collapse: separate; border-spacing: 0; }
.tbl.sticky-head thead th {
  position: sticky;
  top: 57px;
  z-index: 4;
  background: #f8fafc;
  box-shadow: 0 1px 0 var(--line);
}
.tbl.sticky-head thead th.actions { z-index: 4; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; }
.b-draft { background: #eef2f7; color: #475569; }
.b-pending { background: #fef3c7; color: #92400e; }
.b-approved, .b-confirmed, .b-closed, .b-completed, .b-started, .b-paid { background: #dcfce7; color: #166534; }
.b-partial, .b-started { background: #dbeafe; color: #1e40af; }
.b-received, .b-shipped { background: #dcfce7; color: #166534; }
.b-cancelled { background: #fee2e2; color: #991b1b; }
.b-finished { background: #e0e7ff; color: #3730a3; }
.b-material { background: #f1f5f9; color: #334155; }
.b-semi { background: #fef3c7; color: #92400e; }
.b-unpaid { background: #fee2e2; color: #991b1b; }
.b-viewer { background: #eef2f7; color: #475569; }

.btn { display: inline-block; padding: 7px 14px; border-radius: 8px; border: 1px solid var(--line); background: #fff; color: var(--ink); font-size: 13px; cursor: pointer; text-decoration: none; }
.btn:hover { border-color: var(--brand); color: var(--brand); text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.warn { background: var(--warn); border-color: var(--warn); color: #fff; }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.ghost { background: transparent; }
.btn.sm { padding: 4px 9px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

form.f { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
form.f .wide { grid-column: 1 / -1; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px; font-family: inherit;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid #bfdbfe; border-color: var(--brand); }
.field .unit { position: relative; }
.field .unit input { padding-right: 34px; }
.field .unit span { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 12px; }

.row-items { border: 1px solid var(--line); border-radius: 8px; overflow: auto; }
.row-items table { width: 100%; border-collapse: collapse; }
.row-items th { background: #f8fafc; font-size: 12px; color: var(--muted); padding: 8px; border-bottom: 1px solid var(--line); text-align: left; }
.row-items td { padding: 6px 8px; border-bottom: 1px solid #f1f5f9; }
.row-items input, .row-items select, .row-items textarea { width: 100%; min-width: 0; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; font: inherit; }
.row-items input[type="number"] { text-align: right; font-variant-numeric: tabular-nums; }
.row-items textarea[data-autosize] { min-height: 32px; line-height: 1.35; resize: none; overflow: hidden; overflow-wrap: anywhere; }
.row-items table.order-lines { table-layout: fixed; min-width: 960px; }
.row-items table.order-lines th, .row-items table.order-lines td { vertical-align: middle; overflow-wrap: anywhere; word-break: break-word; }
.row-items table.order-lines th { white-space: normal; }
.row-items table.order-lines th.num, .row-items table.order-lines td.num { text-align: right; }
.row-items .del { color: var(--bad); cursor: pointer; background: none; border: none; font-size: 15px; }

.filter-bar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.filter-bar input, .filter-bar select { padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 13px; }
.filter-bar .spacer { flex: 1; }

.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; }
.detail-grid .item .k { font-size: 12px; color: var(--muted); }
.detail-grid .item .v { font-size: 15px; font-weight: 600; }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; font-size: 13px; }
.flash.ok { background: #dcfce7; color: #166534; }
.flash.err { background: #fee2e2; color: #991b1b; }

.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg,#14213d,#1d4ed8); padding: 20px; }
.login-card { background: #fff; border-radius: 14px; padding: 34px 36px; width: 380px; max-width: 100%; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.login-card h1 { font-size: 20px; margin: 0 0 4px; }
.login-card .sub { color: var(--muted); font-size: 13px; margin-bottom: 20px; }
.login-card label { font-size: 12px; color: var(--muted); display: block; margin: 12px 0 4px; }
.login-card input { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px; }
.login-card .btn { width: 100%; margin-top: 18px; padding: 10px; font-size: 15px; }
.muted { color: var(--muted); }
.mt { margin-top: 12px; }
.mb { margin-bottom: 12px; }
.right { text-align: right; }
.flex { display: flex; align-items: center; gap: 8px; }
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.empty { text-align: center; color: var(--muted); padding: 30px 0; }
.tabbar { display: flex; gap: 6px; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.tabbar a { padding: 8px 14px; border-bottom: 2px solid transparent; color: var(--muted); font-size: 14px; }
.tabbar a.active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; text-decoration: none; }
@media (max-width: 860px) {
  /* 平板/窄屏：侧边栏收窄为图标栏 */
  .sidebar { width: 64px; flex-basis: 64px; }
  .sidebar .logo span, .sidebar .ver { display: none; }
  .sidebar nav a { justify-content: center; font-size: 0; gap: 0; }
  .sidebar nav a:after { content: attr(data-short); font-size: 11px; }
}

@media (max-width: 768px) {
  /* 手机：侧边栏改为抽屉，主内容全宽 */
  :root { --mobile-topbar-h: calc(50px + env(safe-area-inset-top)); }
  .layout { display: block; }
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; width: 250px; flex-basis: auto;
    transform: translateX(-100%); transition: transform .22s ease; z-index: 40;
    padding-top: env(safe-area-inset-top);
  }
  .sidebar nav a { justify-content: flex-start; font-size: 14px; gap: 9px; }
  .sidebar nav a:after { content: none; }
  .sidebar-mobile-user {
    display: flex; flex-direction: column; padding: 10px 16px 8px;
    border-bottom: 1px solid rgba(255,255,255,.08);
  }
  .sidebar-mobile-user b { color: #fff; font-size: 14px; }
  .sidebar-mobile-user span { color: #8fa3c8; font-size: 12px; }
  .sidebar-mobile-search { display: block; padding: 10px 12px 2px; }
  .sidebar-mobile-search input {
    width: 100%; padding: 9px 11px; border: 1px solid rgba(255,255,255,.18);
    border-radius: 8px; background: rgba(255,255,255,.1); color: #fff; font-size: 14px;
  }
  .sidebar-mobile-search input::placeholder { color: #9fb0cc; }
  .mask.show { display: block; }
  .burger { display: inline-block; }
  .topbar {
    padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
    gap: 6px; min-height: var(--mobile-topbar-h);
  }
  .topbar .crumbs-txt { display: none; }
  .topbar .user .who { display: none; }
  .search-bar { display: none; }
  .topbar .user { gap: 6px; min-width: 0; overflow-x: auto; scrollbar-width: none; }
  .topbar .user::-webkit-scrollbar { display: none; }
  .topbar .user .mobile-secondary-action { display: none !important; }
  .sidebar-mobile-actions {
    display: flex; flex-direction: column; gap: 2px; padding: 10px 12px;
    border-top: 1px solid rgba(255,255,255,.1);
  }
  .sidebar-mobile-actions a {
    color: #dbe5f5; padding: 10px 12px; border-radius: 8px; font-size: 13px;
  }
  .sidebar-mobile-actions a:hover { background: rgba(255,255,255,.08); color: #fff; text-decoration: none; }
  .desktop-org-switch { display: none !important; }
  .mobile-org-switch {
    display: flex; align-items: center; gap: 9px; padding: 8px 12px;
    position: sticky; top: var(--mobile-topbar-h); z-index: 4; background: #eef4ff;
    border-bottom: 1px solid #cbd9f2; box-shadow: 0 3px 8px rgba(15,23,42,.06);
  }
  .mobile-org-switch label { flex: 0 0 auto; font-size: 12px; font-weight: 700; color: #31548f; }
  .mobile-org-switch form { flex: 1; min-width: 0; }
  .mobile-org-switch select {
    width: 100%; padding: 8px 10px; border: 1px solid #9fb6df; border-radius: 8px;
    background: #fff; color: var(--ink); font-size: 14px; font-weight: 600;
  }
  .content { padding: 14px 12px calc(30px + env(safe-area-inset-bottom)); }
  .page-head h1 { font-size: 17px; }
  .page-head .flex { flex-wrap: wrap; }
  /* 手机审批：操作按钮全宽大按钮，便于点按 */
  .page-head .flex form { flex: 1 1 100%; }
  .page-head .flex form .btn, .page-head .flex > .btn { width: 100%; padding: 12px; font-size: 15px; }
  .card { padding: 12px; overflow-x: auto; }
  .card h3 { font-size: 14px; }
  /* 双列网格在手机上强制单列 */
  .grid { grid-template-columns: 1fr !important; }
  /* 页签/过滤条横向滚动 */
  .tabbar { overflow-x: auto; white-space: nowrap; }
  .tabbar a { padding: 8px 12px; }
  .filter-bar { flex-wrap: wrap; }
  .filter-bar input, .filter-bar select { flex: 1 1 140px; min-width: 0; }
  /* iPhone Safari 对小于 16px 的输入框会自动放大页面，手机端统一为 16px。 */
  .field input, .field select, .field textarea,
  .filter-bar input, .filter-bar select,
  .row-items input, .row-items select, .row-items textarea,
  .ss-input, .sidebar-mobile-search input,
  .mobile-org-switch select, .login-card input {
    font-size: 16px;
  }
  .row-items { -webkit-overflow-scrolling: touch; }
  .tbl th, .tbl td { padding: 7px 8px; }
  .tbl.sticky-head thead th { top: calc(var(--mobile-topbar-h) + 48px); }
  .stat .num { font-size: 20px; }
  .detail-grid { gap: 8px; }
  /* 大按钮更好点 */
  .btn { padding: 8px 13px; }
  .btn.sm { padding: 6px 10px; }
  .login-card { padding: 26px 22px; }
}

/* ---- 待办/消息数量角标 ---- */
.todo-badge {
  display: inline-block; min-width: 17px; padding: 0 5px; margin-left: 4px;
  border-radius: 99px; background: var(--bad, #dc2626); color: #fff;
  font-size: 11px; font-weight: 700; line-height: 17px; text-align: center; vertical-align: 1px;
}
.todo-badge.warn { background: var(--warn, #d97706); }
.sidebar nav a .todo-badge { background: #f59e0b; }

/* ---- 账号切换横幅 ---- */
.switch-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  padding: 8px 22px; background: #eff6ff; border-bottom: 1px solid #bfdbfe;
  color: #1e40af; font-size: 13px;
}
.switch-banner b { color: #1d4ed8; }
.switch-banner .btn { border-color: #bfdbfe; background: #fff; }
.sim-tag {
  display: inline-block; margin-left: 5px; padding: 1px 7px; border-radius: 99px;
  background: #fef3c7; color: #92400e; font-size: 11px; font-weight: 600;
}

/* ================= 滚动条始终显示（不自动隐藏） ================= */
/* macOS 系统默认"自动隐藏"滚动条，这里强制所有页面滚动条常显 */
html, body {
  scrollbar-width: thin;               /* Firefox */
  scrollbar-color: #94a3b8 #e2e8f0;    /* Firefox */
}
* {
  scrollbar-width: thin;               /* Firefox 全局 */
  scrollbar-color: #94a3b8 #e2e8f0;
}
/* WebKit/Blink（Chrome/Safari/Edge）经典滚动条：常显 */
::-webkit-scrollbar {
  width: 11px;
  height: 11px;
  -webkit-appearance: none;
}
::-webkit-scrollbar-track {
  background: #eef2f7;
  border-radius: 6px;
}
::-webkit-scrollbar-thumb {
  background: #94a3b8;
  border-radius: 6px;
  border: 2px solid #eef2f7;
}
::-webkit-scrollbar-thumb:hover {
  background: #64748b;
}
::-webkit-scrollbar-corner {
  background: #eef2f7;
}
/* 侧边栏、卡片内表格等内部滚动容器也常显 */
.sidebar nav,
.card,
.tbl-wrap,
.content,
.filter-bar {
  scrollbar-width: thin;
  scrollbar-color: #94a3b8 #e2e8f0;
}

/* ---- 商标 Logo ---- */
.logo-img { display: block; max-width: 150px; height: auto; margin: 0 auto 6px; }
.login-logo { max-width: 240px; height: auto; margin: 0 auto 10px; display: block; }
@media (max-width: 720px) {
  .login-logo { max-width: 200px; }
}

/* ---- 通用可搜索下拉（客户/产品/供应商等选择框自动增强） ---- */
.ss-wrap { position: relative; display: block; width: 100%; }
.ss-input { width: 100%; padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 13px; background: #fff; }
.ss-input:focus { border-color: var(--brand); outline: none; }
.ss-list {
  position: fixed;
  z-index: 200;
  max-height: 360px;
  overflow-y: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 12px 30px rgba(15,23,42,.2);
}
.ss-opt { padding: 7px 10px; font-size: 13px; cursor: pointer; line-height: 1.4; }
.ss-opt:hover { background: #eff6ff; }
.ss-opt:focus { background: #dbeafe; outline: 2px solid #93c5fd; outline-offset: -2px; }
.ss-opt.ss-disabled { color: #9ca3af; cursor: not-allowed; }
.ss-empty { padding: 10px; color: var(--muted); font-size: 12px; }

/* ---- BOM 物料选择器 ---- */
.mat-picker { position: relative; }
.mat-picker .mat-search { width: 100%; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; font-size: 13px; }
.mat-picker .mat-list {
  position: absolute; z-index: 20; top: 100%; left: 0; right: 0; max-height: 180px; overflow-y: auto;
  background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 4px 14px rgba(15,23,42,.12);
}
.mat-picker .mat-opt { padding: 6px 10px; font-size: 13px; cursor: pointer; border-bottom: 1px solid #f1f5f9; }
.mat-picker .mat-opt:hover { background: #eff6ff; }
.mat-picker .mat-empty { padding: 8px 10px; color: var(--muted); font-size: 12px; }
