:root {
  color-scheme: light;
  --background: #f2f2f2;
  --surface: #ffffff;
  --surface-soft: #fafafa;
  --border: #e6e6e6;
  --text: #333333;
  --muted: #888888;
  --primary: #009688;
  --primary-hover: #00877a;
  --danger: #ff5722;
  --warning: #ffb800;
  font-family: "Helvetica Neue", Helvetica, "PingFang SC", Tahoma, Arial, sans-serif;
  font-size: 14px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; }
body { margin: 0; color: var(--text); background: var(--background); line-height: 1.55; }
a { color: inherit; text-decoration: none; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 8px; font-size: 28px; font-weight: 500; }
h2 { margin-bottom: 4px; font-size: 20px; font-weight: 500; }
p { margin-bottom: 0; color: var(--muted); }
small { display: block; color: var(--muted); }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  min-height: 58px;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { font-size: 20px; font-weight: 700; white-space: nowrap; }
.top-actions { display: flex; align-items: center; gap: 20px; }
.top-actions > a { color: #555; }
.top-actions > a:hover { color: var(--primary); }
.top-actions form { margin: 0; }

.page { width: min(1680px, calc(100% - 32px)); margin: 16px auto 40px; }
.panel, .stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 2px;
}
.dashboard-hero, .section-panel { padding: 24px; }
.section-panel { margin-top: 16px; scroll-margin-top: 74px; }
.dashboard-title-row, .section-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
}
.period-label { color: var(--muted); text-align: right; }
.notice, .form-error {
  margin: 14px 0;
  padding: 10px 12px;
  background: #f0f9f7;
  border-left: 3px solid var(--primary);
  color: #16796f;
}
.form-error { background: #fff3ef; border-left-color: var(--danger); color: #bf3f18; }

label { display: grid; gap: 6px; color: #666; }
input, select {
  width: 100%;
  height: 38px;
  padding: 0 10px;
  color: var(--text);
  background: #fff;
  border: 1px solid #dcdfe6;
  border-radius: 2px;
  font: inherit;
}
input:focus, select:focus { border-color: var(--primary); outline: 2px solid rgb(0 150 136 / 12%); }
.button {
  min-height: 38px;
  padding: 0 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 2px;
  color: #fff;
  background: #909399;
  font: inherit;
  cursor: pointer;
}
.button-primary, .button-save { background: var(--primary); }
.button-primary:hover, .button-save:hover { background: var(--primary-hover); }
.button-danger { background: var(--danger); }
.button-neutral { color: #555; background: #eeeeee; }

.filter-grid {
  margin-top: 20px;
  display: grid;
  grid-template-columns: minmax(180px, 1.1fr) minmax(130px, .7fr) minmax(150px, .8fr) minmax(150px, .8fr) minmax(220px, 1.3fr) 120px;
  align-items: end;
  gap: 12px;
}
.stats-grid {
  margin-top: 16px;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
}
.stat-card { min-height: 108px; padding: 18px; border-top: 3px solid var(--primary); }
.stat-card span { color: var(--muted); }
.stat-card strong { margin-top: 10px; display: block; font-size: 24px; font-weight: 500; }

.ledger-list { margin-top: 18px; border: 1px solid var(--border); }
.ledger-list-head, .ledger-record-summary {
  display: grid;
  grid-template-columns: 1.2fr 1.35fr .7fr 1.1fr 1.3fr .8fr .65fr;
  gap: 14px;
  align-items: center;
}
.ledger-list-head { padding: 12px 14px; color: #666; background: var(--surface-soft); border-bottom: 1px solid var(--border); }
.ledger-record { border-bottom: 1px solid var(--border); }
.ledger-record:last-child { border-bottom: 0; }
.ledger-record-summary { padding: 14px; cursor: pointer; list-style: none; }
.ledger-record-summary::-webkit-details-marker { display: none; }
.ledger-record[open] > .ledger-record-summary { background: #f7fbfa; }
.record-time, .record-member, .record-business, .record-status { min-width: 0; }
.record-time strong, .record-member strong, .record-business strong { display: block; font-weight: 500; }
.record-amount { color: #16a085; font-size: 17px; font-weight: 600; }
.details-link { color: var(--primary); }
.status-badge { margin: 0 5px 4px 0; padding: 2px 7px; display: inline-block; border-radius: 2px; font-size: 12px; }
.status-valid { color: #16796f; background: #e8f7f4; }
.status-warning { color: #a56b00; background: #fff6dc; }

.entry-editor { padding: 18px; background: var(--surface-soft); border-top: 1px solid var(--border); }
.entry-editor-heading { margin-bottom: 14px; }
.supplement-form-expanded {
  display: grid;
  grid-template-columns: repeat(6, minmax(120px, 1fr));
  gap: 12px;
  align-items: end;
}
.editor-actions { display: flex; align-items: end; }
.automatic-form { margin-top: 12px; }

.two-column-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.table-scroll { margin-top: 16px; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 12px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--border); }
th { color: #555; background: var(--surface-soft); font-weight: 500; white-space: nowrap; }
td small { margin-top: 2px; }

.report-grid { margin-top: 16px; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.report-grid article { padding: 18px; background: var(--surface-soft); border: 1px solid var(--border); }
.report-grid strong { margin: 8px 0 2px; display: block; font-size: 23px; font-weight: 500; }
.action-row, .mapping-actions { margin-top: 14px; display: flex; flex-wrap: wrap; gap: 10px; }
.inline-form { margin-top: 14px; display: flex; align-items: end; gap: 10px; }
.inline-form label { min-width: 220px; }
.mapping-actions { justify-content: space-between; }
.mapping-actions .inline-form { margin-top: 0; }
.muted-line { margin-top: 12px; }
.empty-state { min-height: 110px; padding: 26px 12px; display: grid; place-content: center; gap: 5px; text-align: center; color: var(--muted); }
.empty-state strong { color: #555; }
.pagination { margin-top: 16px; display: flex; justify-content: flex-end; gap: 8px; }

.login-page { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-panel { width: min(420px, 100%); padding: 34px; background: #fff; border: 1px solid var(--border); border-radius: 2px; }
.login-panel h1 { margin-top: 24px; }
.login-panel form { display: grid; gap: 14px; }
.login-panel > small { margin-top: 18px; text-align: center; }

@media (max-width: 1100px) {
  .filter-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .stats-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .supplement-form-expanded { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .ledger-list { overflow-x: auto; }
  .ledger-list-head, .ledger-record-summary { min-width: 1050px; }
}

@media (max-width: 700px) {
  h1 { font-size: 23px; }
  .topbar { position: static; min-height: auto; padding: 12px; align-items: flex-start; }
  .top-actions { justify-content: flex-end; flex-wrap: wrap; gap: 8px 12px; }
  .top-actions > a { display: none; }
  .page { width: calc(100% - 16px); margin-top: 8px; }
  .dashboard-hero, .section-panel { padding: 14px; }
  .dashboard-title-row, .section-heading { display: block; }
  .period-label { margin-top: 8px; text-align: left; }
  .filter-grid, .stats-grid, .two-column-grid, .report-grid, .supplement-form-expanded { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .stat-card { min-height: 90px; padding: 13px; }
  .stat-card strong { font-size: 19px; }
  .mapping-actions, .inline-form { display: grid; grid-template-columns: 1fr; }
  .inline-form label { min-width: 0; }
  .button { width: 100%; }
  .ledger-list-head, .ledger-record-summary { min-width: 950px; }
}
