html {
  font-size: 14px;
}

@media (min-width: 768px) {
  html {
    font-size: 16px;
  }
}

.btn:focus, .btn:active:focus, .btn-link.nav-link:focus, .form-control:focus, .form-check-input:focus {
  box-shadow: 0 0 0 0.1rem white, 0 0 0 0.25rem #258cfb;
}

html {
  position: relative;
  min-height: 100%;
}

body {
  margin-bottom: 60px;
}

/* ==========================================================================
   预算填报表（Views/Filing/Edit.cshtml）
   作用域限定在 .sheet-page，不改动其他页面的 Bootstrap 默认外观。
   口径：涨红跌绿（中国财务习惯）；金额一律等宽数字右对齐。
   ========================================================================== */

.sheet-page {
  --paper: #fff;
  --ink-1: #14181d;
  --ink-2: #3c444d;
  --ink-3: #5c6570;
  --ink-4: #6f7883;
  --rule: #e4e7eb;
  --rule-2: #ccd2d9;
  --tint: #f6f7f9;
  --tint-2: #eceff3;
  --accent: #0a58ca;
  --accent-tint: #eaf1fb;
  --up: #b3261e;
  --up-soft: #ffb4ad;
  --down: #1a7f45;
  --down-soft: #92e3b0;
  --warn-ink: #7a5200;
  --warn-rule: #dcb265;
  --warn-tint: #fff8e8;

  color: var(--ink-1);
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Source Han Sans SC",
    system-ui, -apple-system, "Segoe UI", sans-serif;
  caret-color: var(--accent);
}

.sheet-page ::selection {
  background: var(--accent-tint);
  color: var(--ink-1);
}

.sheet-page a {
  color: var(--accent);
}

.sheet-page :focus-visible:not(.btn) {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* —— 抬头 —— */

.sheet-masthead {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: .75rem 2rem;
  flex-wrap: wrap;
  padding-bottom: .8rem;
  border-bottom: 2px solid var(--ink-1);
}

.sheet-masthead h1 {
  margin: 0 0 .5rem;
  font-size: 1.375rem;
  font-weight: 650;
  letter-spacing: -.01em;
  line-height: 1.25;
}

.sheet-meta {
  display: flex;
  flex-wrap: wrap;
  gap: .25rem 1.35rem;
  margin: 0;
  font-size: .8125rem;
  line-height: 1.5;
}

.sheet-meta > div {
  display: flex;
  gap: .4rem;
  align-items: baseline;
}

.sheet-meta dt {
  margin: 0;
  font-weight: 400;
  color: var(--ink-4);
}

.sheet-meta dd {
  margin: 0;
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
}

.sheet-status {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  flex: 0 0 auto;
  padding: .3rem .75rem .3rem .6rem;
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: .8125rem;
  font-weight: 600;
}

.sheet-status::before {
  content: "";
  width: .45rem;
  height: .45rem;
  border-radius: 50%;
  background: currentColor;
}

.sheet-status--draft { color: #46505c; background: var(--tint-2); border-color: var(--rule-2); }
.sheet-status--submitted { color: var(--accent); background: var(--accent-tint); border-color: #b9d2f5; }
.sheet-status--approved { color: #146c43; background: #e7f5ec; border-color: #b3ddc4; }
.sheet-status--returned { color: #a32319; background: #fdecea; border-color: #f2bcb6; }

/* —— 口径说明与提示 —— */

.sheet-rule {
  display: flex;
  flex-wrap: wrap;
  gap: .25rem .6rem;
  margin: .75rem 0 0;
  font-size: .8125rem;
  line-height: 1.6;
  color: var(--ink-3);
}

.sheet-rule strong {
  color: var(--ink-2);
  font-weight: 600;
}

.sheet-notice {
  display: flex;
  flex-wrap: wrap;
  gap: .25rem .6rem;
  margin-top: .75rem;
  padding: .65rem .85rem;
  border: 1px solid var(--warn-rule);
  border-radius: 6px;
  background: var(--warn-tint);
  color: var(--warn-ink);
  font-size: .875rem;
  line-height: 1.55;
}

.sheet-notice strong {
  font-weight: 600;
}

.sheet-errors.validation-summary-valid {
  display: none;
}

.sheet-errors {
  margin-top: .75rem;
  padding: .6rem .85rem;
  border: 1px solid #f2bcb6;
  border-radius: 6px;
  background: #fdecea;
  color: #a32319;
  font-size: .875rem;
}

.sheet-errors ul {
  margin: 0;
  padding-left: 1.1rem;
}

.sheet-empty {
  margin-top: 1rem;
  padding: 2.5rem 1rem;
  border: 1px dashed var(--rule-2);
  border-radius: 6px;
  text-align: center;
  color: var(--ink-3);
  font-size: .875rem;
}

/* —— 分块标题 —— */

.sheet-block-head {
  display: flex;
  align-items: baseline;
  gap: .6rem;
  flex-wrap: wrap;
  margin: 1.5rem 0 .55rem;
}

.sheet-block-head h2 {
  display: flex;
  align-items: baseline;
  gap: .5rem;
  margin: 0;
  font-size: 1rem;
  font-weight: 650;
  letter-spacing: .01em;
}

.sheet-block-head .count {
  font-size: .75rem;
  font-weight: 400;
  color: var(--ink-4);
}

.sheet-block-head .block-total {
  margin-left: auto;
  font-size: .8125rem;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}

.sheet-block-head .block-total b {
  color: var(--ink-1);
  font-weight: 600;
}

/* —— 表格 —— */

.sheet-viewport {
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--paper);
  scrollbar-width: thin;
  scrollbar-color: #b9c1ca transparent;
}

/* 窄屏才允许横向滚动；宽屏保持文档流，表头才能吸附在窗口顶部 */
@media (max-width: 1199.98px) {
  .sheet-viewport {
    overflow-x: auto;
  }
}

.sheet-viewport::-webkit-scrollbar {
  width: 11px;
  height: 11px;
}

.sheet-viewport::-webkit-scrollbar-thumb {
  background: #c2c9d1;
  border: 3px solid #fff;
  border-radius: 8px;
}

.sheet-viewport::-webkit-scrollbar-thumb:hover {
  background: #a8b1bb;
}

.sheet-table {
  width: 100%;
  min-width: 1080px;
  margin: 0;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
  font-size: .875rem;
}

.sheet-table thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  padding: .5rem .55rem;
  background: var(--tint);
  box-shadow: inset 0 -1px 0 var(--rule-2);
  color: var(--ink-2);
  font-size: .8125rem;
  font-weight: 600;
  line-height: 1.3;
  text-align: center;
  vertical-align: middle;
  white-space: nowrap;
}

.sheet-table thead th .sub {
  display: block;
  margin-top: .15rem;
  font-size: .6875rem;
  font-weight: 400;
  letter-spacing: .02em;
  color: var(--ink-4);
}

.sheet-table tbody td,
.sheet-table tbody th {
  padding: .34rem .55rem;
  border-bottom: 1px solid var(--rule);
  vertical-align: middle;
}

.sheet-table tbody tr:hover td,
.sheet-table tbody tr:hover th {
  background: #fafbfc;
}

.sheet-table tbody tr.subtotal:hover td {
  background: var(--tint);
}

.sheet-table .money-start {
  border-left: 1px solid var(--rule);
}

.c-no {
  width: 4%;
  padding-left: .3rem !important;
  padding-right: .3rem !important;
  text-align: center;
  color: var(--ink-4);
  font-variant-numeric: tabular-nums;
}

.cat-cell {
  padding: .34rem .4rem !important;
  border-right: 1px solid var(--rule);
  background: var(--tint);
  color: var(--ink-2);
  font-size: .8125rem;
  font-weight: 600;
  line-height: 1.4;
  text-align: center;
  vertical-align: middle !important;
}

.subject-cell {
  color: var(--ink-1);
  line-height: 1.45;
}

.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  letter-spacing: .01em;
  white-space: nowrap;
}

.num-ro {
  color: var(--ink-3);
}

.num-zero {
  color: var(--ink-4);
}

.num-up {
  color: var(--up);
}

.num-down {
  color: var(--down);
}

/* 决算数钻取 */
.drill {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px dashed currentColor;
}

.drill:hover {
  background: var(--accent-tint);
  border-bottom-style: solid;
}

/* 需说明标记 */
.chip-flag {
  display: none;
  margin-left: .4rem;
  padding: 0 .35rem;
  border: 1px solid var(--warn-rule);
  border-radius: 3px;
  background: var(--warn-tint);
  color: var(--warn-ink);
  font-size: .6875rem;
  font-weight: 600;
  line-height: 1.5;
  white-space: nowrap;
}

.sheet-table tr.needs-reason .chip-flag {
  display: inline-block;
  animation: sheet-chip-in .18s ease-out both;
}

@keyframes sheet-chip-in {
  from { opacity: 0; transform: translateY(-2px); }
  to { opacity: 1; transform: none; }
}

/* 输入控件：默认低调，聚焦时明确 */
.sheet-input {
  width: 100%;
  padding: .22rem .4rem;
  border: 1px solid var(--rule-2);
  border-radius: 4px;
  background: #fff;
  color: var(--ink-1);
  font: inherit;
  font-variant-numeric: tabular-nums;
  line-height: 1.45;
  text-align: right;
  transition: border-color .12s ease, box-shadow .12s ease, background-color .12s ease;
}

.sheet-input:hover {
  border-color: #aab3bd;
}

.sheet-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(10, 88, 202, .16);
}

.sheet-input::placeholder {
  color: var(--ink-4);
}

.sheet-input.js-reason {
  text-align: left;
}

.sheet-input.is-missing {
  border-color: var(--warn-rule);
}

.sheet-input.is-missing:focus {
  border-color: #c68a1f;
  box-shadow: 0 0 0 3px rgba(198, 138, 31, .18);
}

.sheet-input.is-invalid-soft {
  border-color: #e39a93;
}

/* 小计与合计 */
.sheet-table tr.subtotal td {
  background: var(--tint);
  border-bottom: 1px solid var(--rule-2);
  color: var(--ink-2);
  font-weight: 600;
}

.sheet-table tr.subtotal td:first-child {
  text-align: right;
  font-size: .8125rem;
  color: var(--ink-3);
  font-weight: 500;
}

.sheet-table tfoot td {
  padding: .5rem .55rem;
  background: var(--ink-1);
  border-bottom: 0;
  color: #fff;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.sheet-table tfoot td:first-child {
  text-align: right;
  font-size: .8125rem;
}

.sheet-table tfoot .num-up {
  color: var(--up-soft);
}

.sheet-table tfoot .num-down {
  color: var(--down-soft);
}

/* —— 部门总计 —— */

.sheet-total-head {
  width: min(100%, 430px);
  margin: 1.25rem 0 .25rem auto;
  font-size: .8125rem;
  font-weight: 600;
  color: var(--ink-3);
}

.sheet-total {
  width: min(100%, 430px);
  margin: 0 0 0 auto;
  border-collapse: separate;
  border-spacing: 0;
  font-size: .875rem;
}

.sheet-total th {
  padding: .32rem .6rem;
  border-bottom: 1px solid var(--rule);
  color: var(--ink-3);
  font-weight: 500;
  text-align: left;
}

.sheet-total td {
  padding: .32rem .6rem;
  border-bottom: 1px solid var(--rule);
  color: var(--ink-1);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}

.sheet-total tr:last-child th,
.sheet-total tr:last-child td {
  border-bottom: 0;
}

.sheet-total tr:last-child th {
  padding-top: .45rem;
  border-top: 1px solid var(--rule-2);
}

.sheet-total tr:last-child td {
  padding-top: .45rem;
  border-top: 1px solid var(--rule-2);
}

/* —— 操作栏 —— */

.sheet-actions {
  position: sticky;
  bottom: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: .5rem;
  flex-wrap: wrap;
  margin-top: 1rem;
  padding: .7rem .9rem;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: rgba(255, 255, 255, .95);
  backdrop-filter: blur(6px);
  box-shadow: 0 8px 20px -16px rgba(20, 24, 29, .5);
}

.sheet-dirty,
.sheet-missing {
  display: none;
  align-items: center;
  gap: .35rem;
  font-size: .8125rem;
  color: var(--warn-ink);
}

.sheet-dirty::before {
  content: "";
  width: .4rem;
  height: .4rem;
  border-radius: 50%;
  background: currentColor;
}

.sheet-page.is-dirty .sheet-dirty {
  display: inline-flex;
}

.sheet-missing[data-count]:not([data-count="0"]) {
  display: inline-flex;
}

.sheet-hint {
  margin-left: auto;
  font-size: .75rem;
  color: var(--ink-4);
}

.sheet-actions .btn {
  font-size: .875rem;
}

/* 桌面：表头吸附在窗口顶部，操作栏常驻底部 */
@media (min-width: 992px) {
  .sheet-page {
    padding-bottom: 3.75rem;
  }
}

@media (max-width: 991.98px) {
  .sheet-masthead h1 {
    font-size: 1.2rem;
  }

  .sheet-total-head {
    width: 100%;
    margin-left: 0;
  }

  .sheet-total {
    margin-left: 0;
    width: 100%;
  }
}

/* —— 打印：一份能签字的表 —— */

@media print {
  header,
  footer,
  .sheet-actions,
  .no-print {
    display: none !important;
  }

  body {
    margin: 0;
    background: #fff;
  }

  .container-fluid {
    padding: 0 !important;
  }

  .sheet-viewport {
    max-height: none;
    overflow: visible;
    border: 0;
    border-radius: 0;
  }

  .sheet-table {
    min-width: 0;
    font-size: 9.5pt;
  }

  .sheet-table thead {
    display: table-header-group;
  }

  .sheet-table thead th {
    position: static;
  }

  .sheet-table tr {
    break-inside: avoid;
  }

  .sheet-table tfoot td {
    background: #1f262e !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}
