/* ============================================================
   财务台 · 银账设计系统
   纸面 + 墨绿 + 朱砂印 · 账本双细线 · 表格数字
   ============================================================ */

:root {
  --paper: #F4F6F2;
  --card: #FFFFFF;
  --card-soft: #FBFCFA;
  --ink: #1A2420;
  --ink-2: #55605A;
  --ink-3: #6F7973;
  --line: #E2E6E0;
  --line-strong: #C9CEC6;
  --pine: #21573F;
  --pine-strong: #17402E;
  --pine-tint: #EAF1EC;
  --seal: #B5382A;
  --seal-tint: #F9EEEC;
  --brass: #8F6F1F;
  --brass-tint: #F7F1E0;
  --ok: #2E7D5B;
  --ok-tint: #E8F2ED;
  --neutral-fill: #C9CEC6;

  --serif: "Noto Serif SC", "Source Han Serif SC", "Songti SC", SimSun, serif;
  --sans: -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, "SF Mono", Menlo, monospace;

  --shadow-card: 0 1px 2px rgba(26, 36, 32, 0.04), 0 6px 24px rgba(26, 36, 32, 0.05);
  --shadow-pop: 0 4px 12px rgba(26, 36, 32, 0.10), 0 16px 48px rgba(26, 36, 32, 0.12);
  --radius-card: 10px;
  --radius-control: 7px;
  --sidebar-width: 224px;
  --topbar-height: 60px;
  --speed: 160ms;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

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

body {
  background: var(--paper);
  color: var(--ink);
  font: 14px/1.65 var(--sans);
  -webkit-font-smoothing: antialiased;
}

::selection { background: var(--pine-tint); }

h1, h2, h3 { margin: 0; font-weight: 600; }

a { color: var(--pine); }

button { font: inherit; }

:focus-visible {
  outline: 2px solid var(--pine);
  outline-offset: 2px;
  border-radius: 3px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* ---------- 签名元素：账本双细线 ---------- */
.ledger-rule {
  width: 64px;
  height: 5px;
  border-top: 1px solid var(--ink);
  border-bottom: 1px solid var(--ink);
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 4px;
}

.section-title {
  font-family: var(--serif);
  font-size: 16px;
  letter-spacing: 0.05em;
}

.section-head + .section-rule {
  height: 5px;
  border-top: 1px solid var(--ink);
  border-bottom: 1px solid var(--line-strong);
  margin-bottom: 16px;
}

/* ---------- 登录 ---------- */
.login-screen {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(33, 87, 63, 0.06), transparent 60%),
    var(--paper);
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: 44px 44px 32px;
  text-align: center;
}

.login-seal {
  width: 54px;
  height: 54px;
  margin: 0 auto 18px;
  display: grid;
  place-items: center;
  border: 2.5px solid var(--seal);
  border-radius: 9px;
  color: var(--seal);
  font-family: var(--serif);
  font-size: 26px;
  font-weight: 700;
  transform: rotate(-3deg);
}

.login-title {
  font-family: var(--serif);
  font-size: 22px;
  letter-spacing: 0.08em;
}

.login-sub {
  margin: 6px 0 0;
  color: var(--ink-3);
  font-size: 12px;
  letter-spacing: 0.42em;
  text-indent: 0.42em;
}

.login-card .ledger-rule { margin: 18px auto 26px; }

.login-card form { text-align: left; }

.login-foot {
  margin: 26px 0 0;
  color: var(--ink-3);
  font-size: 12px;
}

/* ---------- 表单基件 ---------- */
.field-label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.05em;
  color: var(--ink-2);
  margin: 0 0 6px;
}

.text-input, .select-input {
  width: 100%;
  padding: 10px 12px;
  font: inherit;
  color: var(--ink);
  background: var(--card-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  transition: border-color var(--speed) ease;
}

.text-input:hover, .select-input:hover { border-color: var(--line-strong); }

.text-input:focus, .select-input:focus {
  outline: 2px solid var(--pine);
  outline-offset: 1px;
  border-color: var(--pine);
}

.text-input[readonly] { color: var(--ink-3); background: var(--paper); }

.field-help {
  margin: 6px 0 0;
  font-size: 12.5px;
  color: var(--ink-3);
}

.field-error {
  margin: 10px 0 0;
  font-size: 13px;
  color: var(--seal);
}

.form-row { margin-bottom: 18px; }

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

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 16px;
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
  border-radius: var(--radius-control);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background var(--speed) ease, border-color var(--speed) ease, color var(--speed) ease;
  white-space: nowrap;
}

.btn svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

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

.btn-primary { background: var(--pine); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--pine-strong); }

.btn-secondary { background: var(--card); color: var(--pine); border-color: var(--line-strong); }
.btn-secondary:hover:not(:disabled) { border-color: var(--pine); background: var(--pine-tint); }

.btn-danger { background: var(--card); color: var(--seal); border-color: var(--line-strong); }
.btn-danger:hover:not(:disabled) { border-color: var(--seal); background: var(--seal-tint); }

.btn-ghost { background: none; color: var(--ink-2); border-color: transparent; }
.btn-ghost:hover:not(:disabled) { color: var(--ink); background: rgba(26, 36, 32, 0.05); }

.btn-small { padding: 5px 10px; font-size: 12.5px; }
.btn-block { width: 100%; margin-top: 6px; }

.weekly-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-top: 18px;
}

.weekly-actions .card-note { flex: 1 1 240px; }

.btn.is-busy { position: relative; color: transparent !important; pointer-events: none; }
.btn.is-busy::after {
  content: "";
  position: absolute;
  width: 14px; height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.45);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
.btn-secondary.is-busy::after, .btn-danger.is-busy::after, .btn-ghost.is-busy::after {
  border-color: rgba(33, 87, 63, 0.25);
  border-top-color: var(--pine);
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 应用布局 ---------- */
.app { display: flex; min-height: 100dvh; }

.sidebar {
  width: var(--sidebar-width);
  flex: none;
  display: flex;
  flex-direction: column;
  background: var(--card);
  border-right: 1px solid var(--line);
  position: sticky;
  top: 0;
  height: 100dvh;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 18px 18px 16px;
  border-bottom: 1px solid var(--line);
}

.brand-seal {
  width: 36px; height: 36px;
  flex: none;
  display: grid;
  place-items: center;
  border: 2px solid var(--seal);
  border-radius: 7px;
  color: var(--seal);
  font-family: var(--serif);
  font-size: 17px;
  font-weight: 700;
  transform: rotate(-3deg);
}

.brand-text { line-height: 1.3; }
.brand-text b { display: block; font-family: var(--serif); font-size: 16.5px; letter-spacing: 0.14em; }
.brand-text span { font-size: 11px; color: var(--ink-3); letter-spacing: 0.06em; }

.sidebar-nav { flex: 1; padding: 10px 12px; overflow-y: auto; }

.nav-group-label {
  margin: 16px 8px 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.18em;
  color: var(--ink-3);
}
.nav-group-label:first-child { margin-top: 6px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  margin: 1px 0;
  border-radius: var(--radius-control);
  color: var(--ink-2);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  border-left: 2px solid transparent;
  transition: background var(--speed) ease, color var(--speed) ease;
}

.nav-item svg {
  width: 17px; height: 17px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.6;
  stroke-linecap: round; stroke-linejoin: round;
}

.nav-item:hover { background: rgba(26, 36, 32, 0.045); color: var(--ink); }

.nav-item.is-active {
  background: var(--pine-tint);
  color: var(--pine);
  border-left-color: var(--pine);
  font-weight: 600;
}

.nav-badge {
  margin-left: auto;
  font-style: normal;
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
  color: var(--ink-3);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 99px;
  padding: 0 7px;
  line-height: 18px;
}

.nav-badge-alert { color: var(--seal); background: var(--seal-tint); border-color: transparent; }

.sidebar-foot { padding: 12px 16px 16px; border-top: 1px solid var(--line); }
.sidebar-version { margin: 8px 0 0; font-size: 11.5px; color: var(--ink-3); }

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

.topbar {
  height: var(--topbar-height);
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 28px;
  background: color-mix(in srgb, var(--paper) 86%, transparent);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 40;
}

.page-title { font-family: var(--serif); font-size: 19px; letter-spacing: 0.06em; }

.topbar-right { display: flex; align-items: center; gap: 14px; }

.conn-status { display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--ink-2); }
.conn-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--neutral-fill); }
.conn-status.is-ok .conn-dot { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-tint); }
.conn-status.is-bad .conn-dot { background: var(--seal); box-shadow: 0 0 0 3px var(--seal-tint); }

/* 签名元素：环境印章 */
.env-seal {
  font-family: var(--serif);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.3em;
  text-indent: 0.3em;
  color: var(--seal);
  border: 2px solid var(--seal);
  border-radius: 6px;
  padding: 2px 6px;
  transform: rotate(-3deg);
  user-select: none;
}

.view { flex: 1; padding: 26px 28px 56px; max-width: 1220px; width: 100%; margin: 0 auto; }
.view:focus { outline: none; }

/* ---------- 卡片与网格 ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: 22px 24px;
}

.card + .card, .section + .section { margin-top: 20px; }

.card-title-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 14px; }
.card-title { font-size: 14.5px; font-weight: 600; letter-spacing: 0.03em; }
.card-note { font-size: 12.5px; color: var(--ink-3); }

.grid-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(168px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

/* KPI 台账格 */
.tile {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: 16px 18px 14px;
}

.tile-label { font-size: 12.5px; color: var(--ink-2); letter-spacing: 0.04em; }

.tile-value {
  margin-top: 6px;
  font-size: 30px;
  font-weight: 650;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
}

.tile-value small { font-size: 13px; font-weight: 500; color: var(--ink-3); margin-left: 3px; letter-spacing: 0; }

.tile-sub { margin-top: 5px; font-size: 12px; color: var(--ink-3); font-variant-numeric: tabular-nums; }

.tile.is-alert { border-color: color-mix(in srgb, var(--seal) 42%, var(--line)); }
.tile.is-alert .tile-value { color: var(--seal); }
.tile.is-ok .tile-value { color: var(--pine); }

/* 资格量尺 */
.meter {
  display: flex;
  height: 14px;
  border-radius: 4px;
  overflow: hidden;
  gap: 2px;
  background: transparent;
  margin: 12px 0 10px;
}
.meter i { display: block; height: 100%; border-radius: 3px; }
.meter .m-ok { background: var(--ok); }
.meter .m-rest { background: var(--neutral-fill); }

.meter-legend { display: flex; flex-wrap: wrap; gap: 8px 18px; font-size: 12.5px; color: var(--ink-2); }
.meter-legend b { font-variant-numeric: tabular-nums; color: var(--ink); font-weight: 650; }
.meter-legend .dot { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 6px; vertical-align: 0; }

/* ---------- 状态徽标 ---------- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  border-radius: 5px;
  padding: 1px 8px;
  white-space: nowrap;
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill-ok   { color: var(--ok);   background: var(--ok-tint); }
.pill-warn { color: var(--brass); background: var(--brass-tint); }
.pill-bad  { color: var(--seal);  background: var(--seal-tint); }
.pill-mute { color: var(--ink-2); background: var(--paper); }

.tag-missing {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--seal);
  background: var(--seal-tint);
  border-radius: 4px;
  padding: 1px 6px;
}

/* ---------- 表格（账页） ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius-card); background: var(--card); box-shadow: var(--shadow-card); }

table.ledger { width: 100%; border-collapse: collapse; font-size: 13px; }

table.ledger th {
  position: sticky;
  top: 0;
  background: var(--card-soft);
  color: var(--ink-2);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-align: left;
  padding: 10px 14px;
  border-bottom: 1px solid var(--ink);
  box-shadow: 0 1px 0 var(--line-strong), 0 3px 0 var(--card-soft);
  white-space: nowrap;
}

table.ledger td {
  padding: 9px 14px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

table.ledger tbody tr:last-child td { border-bottom: none; }
table.ledger tbody tr:hover td { background: var(--card-soft); }

td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.mono { font-family: var(--mono); font-size: 12px; color: var(--ink-2); }
td .cell-main { font-weight: 550; }
td .cell-sub { display: block; font-size: 12px; color: var(--ink-3); }

tr.row-missing td { background: color-mix(in srgb, var(--seal-tint) 45%, transparent); }
tr.row-missing:hover td { background: color-mix(in srgb, var(--seal-tint) 70%, transparent); }

/* ---------- 明细/空态/骨架 ---------- */
.empty {
  padding: 44px 24px;
  text-align: center;
  color: var(--ink-2);
}
.empty b { display: block; font-size: 14.5px; color: var(--ink); margin-bottom: 6px; }
.empty p { margin: 0 0 14px; font-size: 13px; }

.skeleton { border-radius: 6px; background: linear-gradient(90deg, var(--line) 25%, var(--paper) 45%, var(--line) 65%); background-size: 240% 100%; animation: shimmer 1.2s ease infinite; }
@keyframes shimmer { to { background-position: -140% 0; } }
.skeleton-row { height: 15px; margin: 13px 0; }

.kv { display: grid; grid-template-columns: minmax(120px, max-content) 1fr; gap: 8px 22px; font-size: 13.5px; }
.kv dt { color: var(--ink-2); }
.kv dd { margin: 0; font-variant-numeric: tabular-nums; word-break: break-all; }
.kv dd.mono { font-family: var(--mono); font-size: 12.5px; }

.inline-note { font-size: 12.5px; color: var(--ink-3); }
.check-row { display: inline-flex; align-items: center; gap: 9px; min-height: 38px; color: var(--ink-2); }
.check-row input { width: 17px; height: 17px; accent-color: var(--pine); }

.banner {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  border: 1px solid var(--line);
  border-left: 3px solid var(--brass);
  background: var(--card);
  border-radius: 8px;
  padding: 12px 16px;
  font-size: 13px;
  color: var(--ink-2);
  margin-bottom: 20px;
}
.banner.banner-alert { border-left-color: var(--seal); }
.banner b { color: var(--ink); }

/* ---------- 页签 ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line-strong); margin-bottom: 18px; }
.tab {
  appearance: none;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  padding: 8px 14px;
  font-size: 13.5px;
  font-weight: 550;
  color: var(--ink-2);
  cursor: pointer;
}
.tab:hover { color: var(--ink); }
.tab.is-active { color: var(--pine); border-bottom-color: var(--pine); font-weight: 650; }
.tab .nav-badge { margin-left: 7px; }

/* ---------- 编辑抽屉 ---------- */
.drawer-mask {
  position: fixed;
  inset: 0;
  background: rgba(26, 36, 32, 0.45);
  z-index: 90;
  display: flex;
  justify-content: flex-end;
  animation: fade var(--speed) ease;
}
@keyframes fade { from { opacity: 0; } }

.drawer {
  width: min(460px, 96vw);
  height: 100%;
  background: var(--card);
  box-shadow: var(--shadow-pop);
  display: flex;
  flex-direction: column;
  animation: slide-in 200ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
@keyframes slide-in { from { transform: translateX(24px); opacity: 0; } }

.drawer-head { padding: 20px 26px 0; }
.drawer-title { font-family: var(--serif); font-size: 17px; letter-spacing: 0.04em; }
.drawer-sub { margin: 4px 0 0; font-size: 12.5px; color: var(--ink-3); }
.drawer-head .ledger-rule { margin: 14px 0 0; }
.drawer-body { flex: 1; overflow-y: auto; padding: 20px 26px; }
.drawer-foot { padding: 14px 26px 20px; border-top: 1px solid var(--line); display: flex; gap: 10px; justify-content: flex-end; }

/* ---------- Toast ---------- */
.toast-region { position: fixed; right: 20px; bottom: 20px; z-index: 200; display: flex; flex-direction: column; gap: 10px; }

.toast {
  display: flex;
  align-items: center;
  gap: 9px;
  background: var(--ink);
  color: #F2F5F1;
  font-size: 13.5px;
  border-radius: 8px;
  padding: 11px 16px;
  box-shadow: var(--shadow-pop);
  animation: toast-in 200ms cubic-bezier(0.2, 0.8, 0.2, 1);
  max-width: 380px;
}
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }
.toast::before { content: ""; width: 7px; height: 7px; border-radius: 50%; flex: none; }
.toast-ok::before { background: #6FBF97; }
.toast-err::before { background: #E58A7C; }

/* ---------- 响应式 ---------- */
@media (max-width: 900px) {
  .app { flex-direction: column; }
  .sidebar {
    position: static;
    width: 100%;
    height: auto;
    min-height: 56px;
    flex-direction: row;
    align-items: center;
    overflow: hidden;
  }
  .sidebar-brand { flex: none; border-bottom: none; border-right: 1px solid var(--line); padding: 9px 11px; }
  .brand-text { display: none; }
  .brand-seal { width: 31px; height: 31px; font-size: 15px; }
  .sidebar-nav {
    display: flex;
    flex: 1 1 auto;
    min-width: 0;
    align-items: center;
    gap: 2px;
    padding: 6px;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: thin;
    white-space: nowrap;
  }
  .nav-group-label { display: none; }
  .nav-item {
    flex: 0 0 auto;
    gap: 6px;
    padding: 9px 10px;
    border-left: none;
    border-bottom: 2px solid transparent;
    white-space: nowrap;
  }
  .nav-item.is-active { border-bottom-color: var(--pine); }
  .nav-badge { margin-left: 2px; padding: 0 5px; }
  .sidebar-foot { flex: none; border-top: none; margin-left: 0; padding: 6px 8px; }
  .sidebar-foot .btn { min-width: 34px; padding: 8px; font-size: 0; }
  .sidebar-foot .btn svg { width: 17px; height: 17px; margin: 0; }
  .sidebar-version { display: none; }
  .view { padding: 18px 14px 48px; }
  .topbar { padding: 0 14px; }
  .table-wrap table.ledger { min-width: 700px; }
  .kv { grid-template-columns: 1fr; gap: 2px 0; }
  .kv dt { margin-top: 8px; }
}

@media (max-width: 520px) {
  .nav-item svg { display: none; }
  .nav-item { padding-inline: 9px; }
  .topbar { height: 58px; }
  .page-title { font-size: 18px; }
  .env-seal { font-size: 11px; }
}
