:root {
  --primary: #3154bc;
  --primary-weak: #edf2ff;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --line: #e4e8f0;
  --text: #202c43;
  --muted: #66738a;
  --green: #059669;
  --red: #dc2626;
  --amber: #b45309;
  --sidebar-w: 184px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font: 14px/1.55 -apple-system, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  color: var(--text); background: var(--bg);
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.mono { font-family: "SF Mono", Menlo, Consolas, monospace; font-size: 12.5px; }
a { color: var(--primary); text-decoration: none; }

/* ---------- 顶栏 ---------- */
#topbar {
  height: 64px; background: #15223d; color: #fff;
  display: flex; align-items: center; gap: 18px; padding: 0 18px;
  position: sticky; top: 0; z-index: 50;
}
.brand { font-size: 18px; font-weight: 700; letter-spacing: 1px; }
.brand span { color: #7ea6ff; }
.company { font-size: 13px; color: #c6d2ec; max-width: 300px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-wrap { position: relative; flex: 1; max-width: 420px; }
#global-search {
  width: 100%; height: 32px; border-radius: 6px; border: none; padding: 0 12px;
  background: rgba(255,255,255,.12); color: #fff; outline: none;
}
#global-search::placeholder { color: #93a3c4; }
.search-result {
  position: absolute; top: 38px; left: 0; right: 0; background: #fff; color: var(--text);
  border-radius: 8px; box-shadow: 0 8px 30px rgba(0,0,0,.18); overflow: hidden; max-height: 380px; overflow-y: auto;
}
.search-result .sr-item { padding: 8px 14px; cursor: pointer; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 10px; }
.search-result .sr-item:hover { background: var(--primary-weak); }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 14px; font-size: 13px; }
.top-right .user { background: rgba(255,255,255,.12); padding: 3px 10px; border-radius: 12px; }

/* ---------- 布局 ---------- */
#layout { display: flex; min-height: calc(100vh - 64px); }
#sidenav {
  width: var(--sidebar-w); background: var(--panel); border-right: 1px solid var(--line);
  padding: 22px 12px; display: flex; flex-direction: column; gap: 2px; flex-shrink: 0;
}
#sidenav a {
  padding: 11px 16px; border-radius: 8px; color: var(--text); font-weight: 500;
}
#sidenav a:hover { background: var(--bg); }
#sidenav a.active { background: var(--primary-weak); color: var(--primary); }
#content { flex: 1; padding: 28px 32px 60px; min-width: 0; }

/* ---------- 通用组件 ---------- */
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.page-head h1 { font-size: 25px; letter-spacing: -.6px; margin: 0; }
.page-head .spacer { flex: 1; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 20px; margin-bottom: 18px;
}
.card h3 { margin: 0 0 10px; font-size: 14.5px; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 14px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 20px; }
.stat .label { color: var(--muted); font-size: 12.5px; }
.stat .value { font-size: 26px; font-weight: 650; letter-spacing: -.7px; margin-top: 9px; }
.stat .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }

table.grid { width: 100%; border-collapse: collapse; background: var(--panel); font-size: 13px; }
.grid th, .grid td { border-bottom: 1px solid var(--line); padding: 11px 12px; text-align: left; white-space: nowrap; }
.grid th { background: #f8fafc; color: var(--muted); font-weight: 600; position: sticky; top: 0; }
.grid tbody tr:hover { background: #f7f9ff; }
.grid td.num, .grid th.num { text-align: right; }
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 10px; max-height: 70vh; }

.btn {
  display: inline-block; border: 1px solid var(--line); background: #fff; color: var(--text);
  border-radius: 7px; padding: 8px 15px; cursor: pointer; font-size: 13px;
}
.btn:hover { border-color: #b9c6e0; background: #f8faff; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: #1e40af; }
.btn.danger { color: var(--red); border-color: #f3c1c1; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.sm { padding: 3px 9px; font-size: 12.5px; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; background: #eef2f7; color: var(--muted); }
.badge.ok { background: #e5f7ef; color: var(--green); }
.badge.blue { background: #e8efff; color: var(--primary); }
.badge.warn { background: #fdf1e0; color: var(--amber); }
.badge.err { background: #fde8e8; color: var(--red); }
.badge.dark { background: #e2e8f0; color: #334155; }

.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 10px; }
.filters select, .filters input {
  height: 36px; border: 1px solid var(--line); border-radius: 7px; padding: 0 8px; background: #fff; font-size: 13px;
}
.filters input { width: 130px; }

.pager { display: flex; gap: 8px; align-items: center; margin-top: 10px; font-size: 13px; }

/* ---------- 表单 ---------- */
.form-grid { display: grid; grid-template-columns: 130px 1fr; gap: 9px 12px; align-items: center; max-width: 560px; }
.form-grid label { color: var(--muted); text-align: right; }
.form-grid input, .form-grid select, .form-grid textarea {
  height: 38px; border: 1px solid var(--line); border-radius: 7px; padding: 0 9px; font-size: 13.5px; width: 100%;
}
.form-grid textarea { height: 64px; padding: 6px 9px; }

/* ---------- 弹窗 / 提示 ---------- */
#modal-root .overlay {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: 100;
  display: flex; align-items: flex-start; justify-content: center; padding: 60px 20px;
}
.dialog {
  background: #fff; border-radius: 12px; width: min(860px, 96vw); max-height: 82vh;
  display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.dialog.narrow { width: min(520px, 96vw); }
.dialog .dlg-head { display: flex; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.dialog .dlg-head h2 { margin: 0; font-size: 16px; flex: 1; }
.dialog .dlg-body { padding: 16px 18px; overflow: auto; }
.dialog .dlg-foot { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; gap: 10px; justify-content: flex-end; }

#toast-wrap { position: fixed; top: 76px; right: 18px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: #111827; color: #fff; border-radius: 8px; padding: 10px 16px; font-size: 13.5px;
  box-shadow: 0 6px 24px rgba(0,0,0,.25); max-width: 420px; white-space: pre-wrap;
}
.toast.err { background: #b91c1c; }
.toast.ok { background: #065f46; }

/* ---------- 时间线 ---------- */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 14px 22px; border-left: 2px solid var(--line); margin-left: 6px; }
.timeline li:last-child { border-left-color: transparent; }
.timeline li::before {
  content: ""; position: absolute; left: -6px; top: 3px; width: 10px; height: 10px;
  border-radius: 50%; background: var(--primary);
}
.timeline .t-meta { color: var(--muted); font-size: 12px; }

.check-line { display: flex; gap: 8px; padding: 4px 0; align-items: baseline; }
.check-line .lv { flex-shrink: 0; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 12px; flex-wrap: wrap; }
.tabs button {
  border: none; background: none; padding: 8px 14px; cursor: pointer; font-size: 13.5px;
  border-bottom: 2px solid transparent; color: var(--muted);
}
.tabs button.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 8px 20px; }
.kv div { padding: 3px 0; }
.kv b { color: var(--muted); font-weight: 500; margin-right: 8px; }
.empty { color: var(--muted); padding: 40px; text-align: center; }
.warning-box { background: #fdf1e0; border: 1px solid #f3ddb8; color: var(--amber); border-radius: 8px; padding: 8px 12px; margin: 8px 0; font-size: 13px; }
.info-box { background: var(--primary-weak); border: 1px solid #d4e2ff; color: #1e40af; border-radius: 8px; padding: 8px 12px; margin: 8px 0; font-size: 13px; }

/* Shared hierarchy and responsive workspace */
:root { --radius: 12px; --shadow: 0 3px 14px rgba(27, 43, 73, .035); }
button, input, select, textarea { font-family: inherit; }
button, a, input, select, textarea { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 3px solid #7b9ae8; outline-offset: 3px; }
#global-search:focus-visible { outline: 2px solid #a8bffc; }
.skip-link { position: fixed; top: -70px; left: 16px; z-index: 300; background: white; padding: 10px 16px; }
.skip-link:focus { top: 8px; }
#sidenav { position: sticky; top: 64px; height: calc(100vh - 64px); }
.nav-label { font-size: 11px; color: var(--muted); letter-spacing: 1.5px; padding: 4px 16px 10px; }
.nav-label:not(:first-child) { margin-top: 22px; }
#sidenav a.active { box-shadow: inset 3px 0 var(--primary); font-weight: 650; }
#topbar .muted { color: #bdc9df; }
#topbar .brand { white-space: nowrap; }
#topbar .company { max-width: 240px; }
#global-search { height: 36px; }
.search-result { top: 43px; }
.search-result button.sr-item { width: 100%; text-align: left; background: white; border: 0; border-bottom: 1px solid var(--line); font: inherit; }
.search-result button.sr-item:hover { background: var(--primary-weak); }
.page-head { margin-bottom: 22px; }
.page-description { margin: 6px 0 0; color: var(--muted); font-size: 13px; }
.eyebrow { color: var(--primary); font-size: 11px; letter-spacing: 2px; font-weight: 600; margin-bottom: 4px; }
.section-label { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: 24px 0 12px; font-size: 13px; font-weight: 600; }
.section-label span, .section-label a { font-size: 12px; font-weight: 400; }
.section-label span { color: var(--muted); }
.card, .stat { border-radius: var(--radius); box-shadow: var(--shadow); }
.stat { min-width: 0; }
.stat .value { font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.stat .value small { font-size: 12px; margin-left: 8px; font-weight: 400; letter-spacing: 0; }
.stat .sub { line-height: 1.7; margin-top: 8px; overflow-wrap: anywhere; }
.inventory-stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.finance-stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.stat.featured { background: #edf2ff; border-color: #d5def8; color: #223f95; }
.stat.featured:hover { border-color: var(--primary); }
.stat.featured .label, .stat.featured .sub { color: #50679d; }
.dashboard-bottom { display: grid; grid-template-columns: 1.4fr 1fr; gap: 18px; margin-top: 24px; }
.quick-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.quick-actions a { padding: 15px; border: 1px solid var(--line); border-radius: 8px; color: var(--text); }
.quick-actions a:hover { background: var(--primary-weak); border-color: #b6c7ed; }
.quick-actions strong, .quick-actions span { display: block; }
.quick-actions strong { font-size: 13px; font-weight: 600; }
.quick-actions span { color: var(--muted); margin-top: 5px; font-size: 12px; }
.attention-list a { display: flex; justify-content: space-between; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--line); color: var(--text); font-size: 13px; }
.attention-list a:hover { color: var(--primary); }
.attention-list strong { font-weight: 600; }
.attention { color: var(--amber); }
.archive-summary { margin: 15px 0 0; font-size: 12px; }
.workflow-help { box-shadow: none; background: transparent; }
.workflow-help summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.workflow-help p { font-size: 13px; line-height: 1.9; }
.grid th { z-index: 2; font-size: 12px; }
.grid td.num { font-variant-numeric: tabular-nums; }
.grid tbody tr:has(input:checked) { background: var(--primary-weak); }
input[type=checkbox] { width: 15px; height: 15px; accent-color: var(--primary); cursor: pointer; }
#stone-table .grid th:first-child, #stone-table .grid td:first-child { position: sticky; left: 0; min-width: 40px; background: var(--panel); }
#stone-table .grid th:nth-child(2), #stone-table .grid td:nth-child(2) { position: sticky; left: 40px; min-width: 116px; background: var(--panel); box-shadow: 2px 0 0 var(--line); }
#stone-table .grid th:nth-child(-n+2) { z-index: 4; background: #f8fafc; }
#stone-table .grid td:nth-child(-n+2) { z-index: 1; }
#stone-table .grid tr:has(input:checked) td { background: var(--primary-weak); }
.filters { gap: 9px; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.selection-bar { position: sticky; bottom: 12px; z-index: 5; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 12px; margin-top: 16px; background: #f7f9fd; border: 1px solid var(--line); border-radius: 9px; box-shadow: var(--shadow); }
.selection-bar > .muted { font-size: 12px; }
.selection-bar > .muted:last-child { flex-basis: 100%; }
#sel-info { margin-right: auto; font-weight: 600; color: var(--text); }
.pager { flex-wrap: wrap; padding-top: 6px; }
.modal-open { overflow: hidden; }
.dialog { max-height: calc(100dvh - 80px); }
.dialog .dlg-foot { flex-wrap: wrap; }
.card:has(> table.grid) { overflow-x: auto; }
@media (min-width: 1500px) { #content { padding-left: 40px; padding-right: 40px; } }
@media (max-width: 1100px) {
  #content { padding: 24px 20px 50px; }
  .inventory-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .finance-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .finance-stats .stat:last-child { grid-column: 1 / -1; }
  .dashboard-bottom { grid-template-columns: 1fr; gap: 0; }
  #top-backup { display: none; }
  #topbar .company { max-width: 170px; }
}
@media (max-width: 760px) {
  :root { --sidebar-w: 132px; }
  #topbar { gap: 12px; padding: 0 16px; height: 60px; }
  #topbar .company { display: none; }
  #layout { min-height: calc(100vh - 60px); }
  #sidenav { top: 60px; height: calc(100vh - 60px); padding: 16px 8px; }
  #sidenav a { padding: 10px 12px; font-size: 13px; }
  .nav-label { padding-left: 12px; font-size: 10px; }
  #content { padding: 20px 16px 40px; }
  .page-head h1 { font-size: 22px; }
  .page-head { gap: 8px; }
  .dashboard-head > div:first-child { width: 100%; }
  .dashboard-head .spacer { display: none; }
  .card, .stat { padding: 15px; }
  .stat .value { font-size: 22px; }
  .cards { gap: 10px; }
  .section-label span { font-size: 11px; }
  .quick-actions { gap: 8px; }
  .quick-actions a { padding: 12px; }
  .filters input { max-width: 100%; }
}
@media (max-width: 520px) {
  #layout { display: block; }
  #sidenav { position: sticky; top: 60px; width: 100%; height: auto; z-index: 40; flex-direction: row; overflow-x: auto; padding: 8px; border-bottom: 1px solid var(--line); gap: 4px; }
  #sidenav a { white-space: nowrap; padding: 8px 12px; }
  #sidenav a.active { box-shadow: inset 0 -2px var(--primary); }
  .nav-label, .top-right { display: none; }
  #content { padding: 20px 12px 40px; }
  .section-label span { max-width: 160px; text-align: right; }
  .form-grid { grid-template-columns: 1fr; gap: 6px; }
  .form-grid label { text-align: left; margin-top: 8px; }
  #modal-root .overlay { padding: 20px 10px; }
  .dialog { max-height: calc(100dvh - 40px); }
  .dialog .dlg-body { padding: 14px; }
  .selection-bar { bottom: 6px; }
  .finance-stats { grid-template-columns: 1fr; }
  .toast { max-width: calc(100vw - 32px); }
}

/* ---------------- 云端版：登录页与用户区 ---------------- */
.login-overlay { position: fixed; inset: 0; z-index: 300; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(1200px 600px at 20% -10%, #1d3557 0%, #0f1b2d 60%, #0a1220 100%); }
.login-overlay.hidden { display: none; }
.login-card { width: min(380px, calc(100vw - 32px)); background: #fff; border-radius: 14px; padding: 28px 26px 20px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, .45); display: flex; flex-direction: column; gap: 10px; }
.login-brand { font-size: 26px; font-weight: 800; letter-spacing: 1px; }
.login-brand span { color: var(--accent, #2563eb); }
.login-sub { color: #64748b; font-size: 13px; margin-bottom: 8px; }
.login-notice { background: #fef3c7; border: 1px solid #fde68a; color: #92400e; border-radius: 8px; padding: 8px 10px; font-size: 12.5px; }
.login-card form { display: grid; gap: 6px; }
.login-card label { font-size: 12.5px; color: #475569; margin-top: 4px; }
.login-card input { border: 1px solid #cbd5e1; border-radius: 8px; padding: 9px 10px; font-size: 14px; }
.login-card input:focus { outline: 2px solid #bfdbfe; border-color: #60a5fa; }
.login-card .btn.primary { margin-top: 10px; padding: 10px; font-size: 14.5px; }
.login-links { display: flex; gap: 14px; justify-content: center; margin-top: 10px; font-size: 12.5px; }
.login-links a { color: #2563eb; text-decoration: none; }
.login-links a:hover { text-decoration: underline; }
.login-hint { color: #94a3b8; font-size: 11.5px; text-align: center; margin-top: 6px; }
#top-user { display: inline-flex; align-items: center; gap: 6px; color: var(--muted, #64748b); }
#top-user a { color: #ef4444; text-decoration: none; margin-left: 4px; }
