:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #1f2937;
  --text-soft: #64748b;
  --text-mute: #94a3b8;
  --brand: #1f6feb;
  --brand-dark: #1a5fd0;
  --brand-soft: #e8f0fe;
  --ok: #12805c;
  --ok-soft: #e6f6f0;
  --warn: #b45309;
  --warn-soft: #fdf3e2;
  --danger: #c0392b;
  --danger-soft: #fdecea;
  --info: #4b5563;
  --info-soft: #eef1f5;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 8px 24px rgba(15, 23, 42, 0.06);
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.08);
  --sidebar: 232px;
  --font: system-ui, -apple-system, 'Segoe UI', 'Microsoft YaHei', 'PingFang SC', 'Hiragino Sans GB', sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}

a {
  color: var(--brand);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

h1,
h2,
h3,
h4 {
  margin: 0;
  font-weight: 600;
  line-height: 1.35;
}

h1 {
  font-size: 20px;
}

h2 {
  font-size: 16px;
}

h3 {
  font-size: 15px;
}

p {
  margin: 0 0 8px;
}

/* ---------- 登录页 ---------- */
.login-page {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 16px 16px;
  background: linear-gradient(160deg, #eef3fb 0%, #f7f9fc 45%, #eaf1fb 100%);
}

.login-main {
  flex: 1;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 28px 24px 24px;
}

.login-card .brand {
  text-align: center;
  margin-bottom: 20px;
}

.login-card .brand .logo {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--brand);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 10px;
}

.login-card .brand p {
  color: var(--text-soft);
  font-size: 13px;
  margin: 6px 0 0;
}

.login-hint {
  margin-top: 16px;
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text-soft);
  font-size: 12px;
}

/* ---------- 主框架 ---------- */
.layout {
  display: flex;
  min-height: 100%;
}

.sidebar {
  width: var(--sidebar);
  flex: 0 0 var(--sidebar);
  background: #10243d;
  color: #cbd7e6;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar .side-head {
  padding: 16px 18px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar .side-head .title {
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.4;
}

.sidebar .side-head .subtitle {
  font-size: 12px;
  color: #8fa4bd;
  margin-top: 2px;
}

.nav {
  flex: 1;
  overflow-y: auto;
  padding: 10px 8px 16px;
}

.nav-group-title {
  font-size: 11px;
  letter-spacing: 0.08em;
  color: #7b8ea6;
  padding: 12px 10px 6px;
  text-transform: uppercase;
}

.nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  color: #cbd7e6;
  font-size: 14px;
  text-decoration: none;
  margin-bottom: 2px;
}

.nav a:hover {
  background: rgba(255, 255, 255, 0.07);
  text-decoration: none;
}

.nav a.active {
  background: var(--brand);
  color: #fff;
  font-weight: 500;
}

.nav a .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #f59e0b;
  flex: 0 0 6px;
}

.nav a .count {
  margin-left: auto;
  background: rgba(255, 255, 255, 0.16);
  border-radius: 10px;
  padding: 0 7px;
  font-size: 12px;
}

.side-foot {
  padding: 12px 16px 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 12px;
  color: #93a7c0;
}

.side-foot .who {
  color: #e6edf5;
  font-size: 13px;
  margin-bottom: 2px;
}

.side-foot .links {
  margin-top: 8px;
  display: flex;
  gap: 12px;
}

.side-foot .links a {
  color: #a9bcd4;
}

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

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar .menu-btn {
  display: none;
}

.topbar h1 {
  font-size: 17px;
}

.topbar .spacer {
  flex: 1;
}

.content {
  padding: 18px 20px 40px;
  flex: 1;
  min-width: 0;
}

/* ---------- 底边栏：版权标识与版本号 ---------- */
.app-footer {
  padding: 12px 20px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-mute);
  font-size: 12px;
  line-height: 1.7;
  text-align: center;
  word-break: break-word;
}

.app-footer .copy {
  color: var(--text-soft);
}

.app-footer .ver {
  color: var(--text-mute);
  white-space: nowrap;
}

.login-page .app-footer {
  width: 100%;
  max-width: 400px;
  margin-top: 18px;
  border-top: 0;
  background: transparent;
  padding: 0 4px;
}

.mobile-only {
  display: none;
}

/* ---------- 卡片 ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  margin-bottom: 16px;
}

.card > header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.card > header h2,
.card > header h3 {
  font-size: 15px;
}

.card > header .spacer {
  flex: 1;
}

.card .card-body {
  padding: 16px;
}

.card .card-body.tight {
  padding: 8px 16px 16px;
}

.card .card-foot {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

/* ---------- 统计卡 ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
}

.stat .label {
  color: var(--text-soft);
  font-size: 13px;
}

.stat .value {
  font-size: 24px;
  font-weight: 600;
  margin-top: 4px;
  line-height: 1.2;
}

.stat .value small {
  font-size: 13px;
  font-weight: 400;
  color: var(--text-soft);
  margin-left: 4px;
}

.stat .hint {
  color: var(--text-mute);
  font-size: 12px;
  margin-top: 2px;
}

.stat.warn .value {
  color: var(--warn);
}

.stat.brand .value {
  color: var(--brand);
}

/* ---------- 表格 ---------- */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  min-width: 640px;
}

table.data th,
table.data td {
  padding: 9px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

table.data th {
  background: var(--surface-2);
  color: var(--text-soft);
  font-weight: 500;
  white-space: nowrap;
  position: sticky;
  top: 0;
}

table.data tbody tr:hover {
  background: #fbfcfe;
}

table.data td.num,
table.data th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

table.data td.actions,
table.data th.actions {
  white-space: nowrap;
  text-align: right;
}

table.data tr.subtotal {
  background: var(--surface-2);
  font-weight: 600;
}

table.data .muted {
  color: var(--text-soft);
  font-size: 12.5px;
}

/* ---------- 徽章 ---------- */
.badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 12px;
  line-height: 1.7;
  white-space: nowrap;
  border: 1px solid transparent;
}

.badge.ok {
  background: var(--ok-soft);
  color: var(--ok);
  border-color: #bfe6d8;
}

.badge.warn {
  background: var(--warn-soft);
  color: var(--warn);
  border-color: #f3dcb5;
}

.badge.danger {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: #f6cfc9;
}

.badge.brand {
  background: var(--brand-soft);
  color: var(--brand-dark);
  border-color: #c7dbfa;
}

.badge.info {
  background: var(--info-soft);
  color: var(--info);
  border-color: #dbe1e9;
}

.badge.plain {
  background: transparent;
  color: var(--text-soft);
  border-color: var(--border-strong);
}

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-size: 13.5px;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s ease, border-color 0.12s ease;
}

.btn:hover:not(:disabled) {
  background: var(--surface-2);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn.primary {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

.btn.primary:hover:not(:disabled) {
  background: var(--brand-dark);
}

.btn.danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.btn.danger:hover:not(:disabled) {
  background: #a93226;
}

.btn.ghost {
  border-color: transparent;
  background: transparent;
  color: var(--brand);
  padding: 5px 8px;
}

.btn.ghost:hover:not(:disabled) {
  background: var(--brand-soft);
}

.btn.small {
  padding: 4px 10px;
  font-size: 12.5px;
}

.btn.block {
  width: 100%;
}

.btn-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

/* ---------- 表单 ---------- */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px 16px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.field.wide {
  grid-column: 1 / -1;
}

.field label {
  font-size: 13px;
  color: var(--text-soft);
}

.field label .req {
  color: var(--danger);
  margin-left: 2px;
}

.field .help {
  font-size: 12px;
  color: var(--text-mute);
}

.field .error {
  font-size: 12px;
  color: var(--danger);
}

input[type='text'],
input[type='number'],
input[type='password'],
input[type='date'],
input[type='search'],
select,
textarea {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid var(--brand-soft);
  border-color: var(--brand);
}

input:disabled,
select:disabled,
textarea:disabled {
  background: var(--surface-2);
  color: var(--text-soft);
}

textarea {
  min-height: 68px;
  resize: vertical;
}

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}

.check input {
  width: auto;
}

.filters {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.filters input,
.filters select {
  width: auto;
  min-width: 130px;
}

/* ---------- 提示条 ---------- */
.notice {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 14px;
  border: 1px solid;
}

.notice.info {
  background: var(--brand-soft);
  border-color: #c7dbfa;
  color: #17417f;
}

.notice.warn {
  background: var(--warn-soft);
  border-color: #f3dcb5;
  color: #8a4a06;
}

.notice.danger {
  background: var(--danger-soft);
  border-color: #f6cfc9;
  color: #96291c;
}

.notice.ok {
  background: var(--ok-soft);
  border-color: #bfe6d8;
  color: #0d6146;
}

.empty {
  padding: 32px 16px;
  text-align: center;
  color: var(--text-mute);
  font-size: 13.5px;
}

.loading {
  padding: 28px;
  text-align: center;
  color: var(--text-mute);
}

/* ---------- 分页 ---------- */
.pager {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-soft);
  flex-wrap: wrap;
}

.pager .spacer {
  flex: 1;
}

/* ---------- 弹窗 ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
  overflow-y: auto;
  z-index: 100;
}

.modal {
  background: var(--surface);
  border-radius: 12px;
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 560px;
}

.modal.wide {
  max-width: 860px;
}

.modal > header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}

.modal > header h3 {
  font-size: 15px;
}

.modal > header .close {
  margin-left: auto;
  border: none;
  background: transparent;
  font-size: 20px;
  line-height: 1;
  color: var(--text-soft);
  cursor: pointer;
  padding: 0 4px;
}

.modal .modal-body {
  padding: 16px 18px;
  max-height: 62vh;
  overflow-y: auto;
}

.modal .modal-foot {
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

/* ---------- 提示消息 ---------- */
.toast-host {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(360px, calc(100vw - 32px));
}

.toast {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  font-size: 13.5px;
  background: #fff;
  border-left: 4px solid var(--info);
  animation: slide-in 0.16s ease;
  word-break: break-word;
}

.toast.ok {
  border-left-color: var(--ok);
}

.toast.error {
  border-left-color: var(--danger);
}

.toast.warn {
  border-left-color: var(--warn);
}

@keyframes slide-in {
  from {
    opacity: 0;
    transform: translateX(12px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* ---------- 图表 ---------- */
.chart {
  width: 100%;
  overflow-x: auto;
}

.chart svg {
  display: block;
  width: 100%;
  height: auto;
  min-width: 420px;
}

.chart .grid-line {
  stroke: var(--border);
  stroke-width: 1;
}

.chart .axis-label {
  fill: var(--text-mute);
  font-size: 11px;
}

.chart .bar-brand {
  fill: var(--brand);
}

.chart .bar-ok {
  fill: var(--ok);
}

.chart .bar-warn {
  fill: #d97706;
}

.chart .line-brand {
  fill: none;
  stroke: var(--brand);
  stroke-width: 2;
}

.chart .line-ok {
  fill: none;
  stroke: var(--ok);
  stroke-width: 2;
}

.chart .line-warn {
  fill: none;
  stroke: #d97706;
  stroke-width: 2;
}

.legend {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  font-size: 12.5px;
  color: var(--text-soft);
  padding: 0 16px 12px;
}

.legend .item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend .swatch {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  display: inline-block;
}

.swatch.brand {
  background: var(--brand);
}

.swatch.ok {
  background: var(--ok);
}

.swatch.warn {
  background: #d97706;
}

/* ---------- 明细行/键值 ---------- */
.kv {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px 18px;
}

.kv .k {
  color: var(--text-soft);
  font-size: 12.5px;
}

.kv .v {
  font-size: 14px;
  word-break: break-word;
}

.timeline {
  list-style: none;
  margin: 0;
  padding: 0;
}

.timeline li {
  padding: 8px 0 8px 16px;
  border-left: 2px solid var(--border);
  font-size: 13px;
  position: relative;
}

.timeline li::before {
  content: '';
  position: absolute;
  left: -5px;
  top: 14px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border-strong);
}

.timeline li.done::before {
  background: var(--ok);
}

.timeline li.active::before {
  background: var(--brand);
}

/* ---------- 明细行编辑 ---------- */
.line-items {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.line-item {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  background: var(--surface-2);
}

.line-item .row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  align-items: end;
}

.line-item .row + .row {
  margin-top: 10px;
}

.line-item .remove {
  align-self: end;
}

.inline-num {
  width: 92px;
  text-align: right;
}

.hint-list {
  margin: 6px 0 0;
  padding-left: 18px;
  font-size: 12.5px;
  color: var(--text-soft);
}

.hint-list li {
  margin-bottom: 2px;
}

.similar-hint {
  font-size: 12.5px;
  color: var(--warn);
  margin-top: 4px;
}

/* ---------- 移动端 ---------- */
@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 60;
    transform: translateX(-100%);
    transition: transform 0.18s ease;
    box-shadow: var(--shadow);
  }

  body.nav-open .sidebar {
    transform: none;
  }

  body.nav-open::after {
    content: '';
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.4);
    z-index: 50;
  }

  .topbar .menu-btn {
    display: inline-flex;
  }

  .content {
    padding: 14px 12px 32px;
  }

  .topbar {
    padding: 10px 12px;
  }

  .mobile-only {
    display: block;
  }

  .app-footer {
    padding: 10px 12px 14px;
  }
}

@media (max-width: 560px) {
  .stat-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  }

  .stat .value {
    font-size: 20px;
  }

  .app-footer {
    font-size: 11px;
  }

  .app-footer .ver {
    display: inline-block;
  }

  .card .card-body {
    padding: 12px;
  }

  .modal-backdrop {
    padding: 16px 10px;
  }
}

@media print {
  .sidebar,
  .topbar,
  .btn,
  .pager {
    display: none !important;
  }
}