:root {
  color-scheme: light;
  --bg: #f5f6f2;
  --surface: #ffffff;
  --surface-soft: #eef3ee;
  --surface-warm: #fbf4e9;
  --ink: #20251f;
  --muted: #667064;
  --line: #d9dfd5;
  --line-strong: #b8c2b4;
  --green: #2c704b;
  --green-strong: #1f5638;
  --green-soft: #e3f0e6;
  --amber: #9a641f;
  --amber-soft: #f8ecd8;
  --red: #b5483f;
  --red-soft: #f8e4e1;
  --blue: #356f8f;
  --blue-soft: #e3eef4;
  --shadow: 0 12px 30px rgba(38, 49, 36, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg);
}

body {
  margin: 0;
  color: var(--ink);
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.45;
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 236px minmax(0, 1fr);
}

.sidebar {
  background: #273328;
  color: #f6fbf4;
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 46px;
}

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: #e9b75b;
  color: #1f2a20;
  display: grid;
  place-items: center;
  font-weight: 800;
}

.brand-title {
  margin: 0;
  font-size: 17px;
  line-height: 1.2;
}

.brand-subtitle {
  margin: 3px 0 0;
  color: #cad7c9;
  font-size: 12px;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.nav-button {
  width: 100%;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #ecf5ea;
  padding: 10px 11px;
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
}

.nav-button:hover,
.nav-button.active {
  background: rgba(255, 255, 255, 0.12);
}

.nav-button.active {
  color: #ffffff;
}

.sidebar-footer {
  margin-top: auto;
  color: #bfd0bd;
  font-size: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.16);
  padding-top: 14px;
}

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

.topbar {
  min-height: 72px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 14px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 5;
}

.topbar h1 {
  margin: 0;
  font-size: 20px;
  line-height: 1.25;
}

.topbar-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.content {
  padding: 22px;
}

.section {
  display: none;
}

.section.active {
  display: block;
}

.section-header {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
  margin-bottom: 18px;
}

.section-title {
  margin: 0;
  font-size: 24px;
  line-height: 1.2;
}

.section-copy {
  margin: 8px 0 0;
  color: var(--muted);
  max-width: 820px;
}

.grid {
  display: grid;
  gap: 14px;
}

.grid.kpi {
  grid-template-columns: repeat(4, minmax(160px, 1fr));
}

.grid.two {
  grid-template-columns: minmax(0, 1.15fr) minmax(320px, 0.85fr);
}

.grid.three {
  grid-template-columns: repeat(3, minmax(190px, 1fr));
}

.card,
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.card {
  padding: 15px;
}

.panel {
  overflow: hidden;
}

.panel-head {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: #fbfcfa;
}

.panel-title {
  margin: 0;
  font-size: 16px;
  line-height: 1.25;
}

.panel-body {
  padding: 16px;
}

.kpi-card {
  display: grid;
  gap: 6px;
}

.kpi-label {
  color: var(--muted);
  font-size: 12px;
}

.kpi-value {
  font-size: 24px;
  font-weight: 800;
  line-height: 1.1;
}

.kpi-note {
  color: var(--muted);
  font-size: 12px;
}

.task-list {
  display: grid;
  gap: 10px;
}

.task-row {
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.task-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: var(--surface-soft);
  color: var(--green-strong);
}

.task-title {
  font-weight: 700;
}

.task-meta {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 26px;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 12px;
  white-space: nowrap;
  border: 1px solid transparent;
}

.status.ok {
  color: var(--green-strong);
  background: var(--green-soft);
  border-color: #bfdac6;
}

.status.warn {
  color: var(--amber);
  background: var(--amber-soft);
  border-color: #ebd2aa;
}

.status.danger {
  color: var(--red);
  background: var(--red-soft);
  border-color: #edc2bd;
}

.status.info {
  color: var(--blue);
  background: var(--blue-soft);
  border-color: #c2d8e4;
}

.status input {
  margin: 0 3px 0 0;
}

.field-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(170px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.field {
  display: grid;
  gap: 6px;
}

.field label {
  color: var(--muted);
  font-size: 12px;
}

.input,
.select,
.textarea {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 8px 10px;
}

.textarea {
  min-height: 80px;
  resize: vertical;
}

.input:focus,
.select:focus,
.textarea:focus {
  outline: 2px solid rgba(44, 112, 75, 0.24);
  border-color: var(--green);
}

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

.button {
  min-height: 38px;
  border-radius: 8px;
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--ink);
  padding: 8px 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  white-space: nowrap;
}

.button:hover {
  border-color: var(--green);
}

.button.primary {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}

.button.primary:hover {
  background: var(--green-strong);
}

.button.warn {
  color: var(--amber);
  border-color: #ddb985;
  background: #fff8ed;
}

.button.danger {
  color: var(--red);
  border-color: #e6aaa4;
  background: #fff6f5;
}

.icon {
  width: 17px;
  height: 17px;
  flex: 0 0 17px;
}

.segmented {
  display: inline-flex;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}

.segment {
  min-height: 36px;
  border: 0;
  border-right: 1px solid var(--line);
  background: transparent;
  padding: 7px 12px;
  color: var(--muted);
}

.segment:last-child {
  border-right: 0;
}

.segment.active {
  background: var(--green);
  color: #fff;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px;
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  background: #fbfcfa;
  position: sticky;
  top: 0;
  z-index: 1;
}

td.number,
th.number {
  text-align: right;
}

.table-input {
  width: 96px;
  min-height: 34px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 6px 8px;
  text-align: right;
}

.table-input.small {
  width: 74px;
}

.money {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.muted {
  color: var(--muted);
}

.mini {
  font-size: 12px;
}

.category-pill {
  display: inline-flex;
  border-radius: 999px;
  background: var(--surface-soft);
  color: #465343;
  padding: 4px 8px;
  font-size: 12px;
  white-space: nowrap;
}

.empty {
  border: 1px dashed var(--line-strong);
  background: #fff;
  border-radius: 8px;
  padding: 18px;
  color: var(--muted);
}

.notice {
  border-left: 4px solid var(--green);
  background: #f7fbf6;
  padding: 12px 14px;
  border-radius: 8px;
  color: #314331;
}

.danger-notice {
  border-left-color: var(--red);
  background: var(--red-soft);
  color: var(--red);
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
}

.login-card {
  width: min(420px, 100%);
  display: grid;
  gap: 14px;
}

.login-brand {
  color: var(--ink);
}

.login-title {
  margin: 0;
  font-size: 24px;
  line-height: 1.2;
}

.login-button {
  width: 100%;
}

.topbar-date {
  width: 156px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 20;
  background: #263127;
  color: #fff;
  padding: 12px 14px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: none;
  max-width: min(360px, calc(100vw - 36px));
}

.toast.show {
  display: block;
}

.progress {
  height: 8px;
  border-radius: 999px;
  background: var(--surface-soft);
  overflow: hidden;
}

.progress span {
  display: block;
  height: 100%;
  background: var(--green);
}

.report-cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.report-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 14px;
}

.report-metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.report-metrics div {
  background: #f8faf7;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
}

.report-metrics span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.report-metrics strong {
  display: block;
  margin-top: 3px;
  font-size: 17px;
}

.purchase-groups {
  display: grid;
  gap: 12px;
}

.purchase-category {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}

.purchase-category-title {
  background: var(--surface-warm);
  border-bottom: 1px solid var(--line);
  padding: 8px 10px;
  font-weight: 800;
}

.compact-table {
  min-width: 0;
}

.compact-table th,
.compact-table td {
  padding: 7px 8px;
}

.log-table {
  min-width: 900px;
}

.log-table td:last-child {
  white-space: normal;
  max-width: 320px;
}

.a4-finance table {
  font-size: 10px;
}

.category-buyer-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.mobile-menu {
  display: none;
}

@media (max-width: 1040px) {
  .grid.kpi,
  .grid.three,
  .report-cards {
    grid-template-columns: repeat(2, minmax(170px, 1fr));
  }

  .grid.two {
    grid-template-columns: 1fr;
  }

  .field-row {
    grid-template-columns: repeat(2, minmax(160px, 1fr));
  }
}

@media (max-width: 760px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 260px;
    z-index: 30;
    transform: translateX(-100%);
    transition: transform 0.18s ease;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .mobile-menu {
    display: inline-flex;
  }

  .topbar {
    position: static;
    align-items: flex-start;
    flex-direction: column;
    padding: 14px;
  }

  .toolbar {
    width: 100%;
    justify-content: flex-start;
  }

  .content {
    padding: 14px;
  }

  .section-header {
    flex-direction: column;
  }

  .grid.kpi,
  .grid.three,
  .field-row,
  .report-cards,
  .category-buyer-grid {
    grid-template-columns: 1fr;
  }

  .task-row {
    grid-template-columns: 32px minmax(0, 1fr);
  }

  .task-row .status {
    grid-column: 2;
    justify-self: start;
  }

  .button {
    min-width: 0;
  }
}

@media print {
  @page {
    size: A4;
    margin: 8mm;
  }

  body {
    background: #fff;
    font-size: 11px;
  }

  .sidebar,
  .topbar,
  .actions,
  .toast,
  .button,
  .mobile-menu {
    display: none !important;
  }

  .app-shell {
    display: block;
  }

  .content {
    padding: 0;
  }

  .card,
  .panel,
  .report-card {
    box-shadow: none;
    border-color: #333;
  }

  .report-cards {
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
  }

  table {
    min-width: 0;
    font-size: 10px;
  }

  th,
  td {
    padding: 3px 4px;
  }
}
