:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --surface: #ffffff;
  --surface-soft: #eef5f6;
  --line: #d8e1e4;
  --line-strong: #b9c8ce;
  --text: #172026;
  --muted: #66757f;
  --accent: #0f766e;
  --accent-strong: #0b5f59;
  --danger: #b42318;
  --danger-bg: #fff1f0;
  --ok-bg: #e8f6ee;
  --pending-bg: #fff7df;
  --shadow: 0 8px 24px rgba(29, 45, 53, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  font-size: 14px;
}

button,
input,
select {
  font: inherit;
}

.date-field {
  position: relative;
  display: grid;
  grid-template-columns: minmax(120px, 1fr) 46px;
  gap: 6px;
  width: 100%;
}

.date-field .date-text {
  min-width: 0;
  font-variant-numeric: tabular-nums;
}

.date-btn {
  height: 34px;
  padding: 0 8px;
  color: var(--accent-strong);
  font-size: 12px;
  background: #ffffff;
}

.date-btn:hover {
  background: var(--surface-soft);
}

.date-picker {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 1px;
  min-width: 1px;
  height: 1px;
  padding: 0;
  opacity: 0;
  pointer-events: none;
}

.date-popover {
  position: fixed;
  z-index: 50;
  width: 248px;
  padding: 10px;
  background: #ffffff;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  box-shadow: 0 12px 32px rgba(23, 32, 38, 0.18);
}

.date-popover-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.date-popover-head button {
  width: 30px;
  height: 28px;
  padding: 0;
  color: var(--accent-strong);
  background: #ffffff;
}

.date-week,
.date-days {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 3px;
}

.date-week span {
  color: var(--muted);
  text-align: center;
  font-size: 12px;
  font-weight: 700;
}

.date-days button {
  height: 28px;
  padding: 0;
  color: var(--text);
  background: #ffffff;
  border-color: transparent;
}

.date-days button:hover {
  color: #ffffff;
  background: var(--accent);
}

.date-days .muted-day {
  color: #a8b3ba;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  height: 76px;
  padding: 14px 24px;
  background: #ffffff;
  border-bottom: 1px solid var(--line);
}

.app-header h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.2;
  font-weight: 700;
}

.app-header p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.header-actions,
.panel-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.current-user {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(23, 32, 38, 0.42);
}

.login-card {
  width: min(100%, 400px);
  padding: 28px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.login-card h2 {
  margin: 0 0 8px;
  font-size: 20px;
}

.login-form,
.account-form {
  display: grid;
  gap: 14px;
  margin-top: 18px;
}

.login-form label,
.account-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.account-modal {
  width: min(100%, 480px);
}

.test-date-control {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.test-date-control input {
  width: 112px;
  min-width: 112px;
  height: 30px;
  padding: 0 8px;
}

.layout {
  display: grid;
  grid-template-columns: 168px minmax(0, 1fr);
  gap: 16px;
  padding: 16px;
}

.workspace {
  min-width: 0;
}

.side-nav {
  position: sticky;
  top: 92px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  height: calc(100vh - 108px);
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.nav-btn {
  width: 100%;
  padding: 10px 12px;
  color: var(--muted);
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
}

.nav-btn:hover,
.nav-btn.active {
  color: var(--accent-strong);
  background: var(--surface-soft);
  border-color: #c9e2e0;
}

.workspace {
  display: grid;
  gap: 16px;
}

.page {
  display: none;
}

.page.active {
  display: grid;
  gap: 16px;
}

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

.panel-title {
  justify-content: space-between;
  min-height: 54px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}

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

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

.form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(180px, 1fr));
  gap: 14px 16px;
  padding: 16px;
}

#entryPage #contractSection .panel-title {
  min-height: 46px;
  padding: 8px 16px;
}

#entryPage #contractSection .form-grid {
  grid-template-columns: repeat(5, minmax(150px, 1fr));
  gap: 10px 12px;
  padding: 12px 16px;
}

#entryPage #feeSection table {
  min-width: 1420px;
}

#entryPage #feeSection th:nth-child(1),
#entryPage #feeSection td:nth-child(1),
#entryPage #feeSection th:nth-child(2),
#entryPage #feeSection td:nth-child(2) {
  width: 220px;
}

#entryPage #feeSection th:nth-child(5),
#entryPage #feeSection td:nth-child(5) {
  width: 260px;
}

#entryPage #feeSection th:nth-child(6),
#entryPage #feeSection td:nth-child(6),
#entryPage #feeSection th:nth-child(7),
#entryPage #feeSection td:nth-child(7) {
  width: 180px;
}

.temp-item-table {
  min-width: 1280px;
}

.temp-item-table th:nth-child(1),
.temp-item-table td:nth-child(1),
.temp-item-table th:nth-child(2),
.temp-item-table td:nth-child(2) {
  width: 220px;
}

.temp-item-table th:nth-child(3),
.temp-item-table td:nth-child(3),
.temp-item-table th:nth-child(4),
.temp-item-table td:nth-child(4) {
  width: 180px;
}

.sub-panel-title {
  border-top: 1px solid var(--line);
}

.query-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(180px, 260px));
  gap: 14px 16px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.report-query-grid {
  grid-template-columns: repeat(5, minmax(160px, 1fr));
}

label {
  display: grid;
  gap: 6px;
  color: #40515b;
  font-size: 12px;
  font-weight: 600;
}

input,
select {
  width: 100%;
  height: 34px;
  padding: 6px 8px;
  color: var(--text);
  background: #ffffff;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  outline: none;
}

input[type="checkbox"] {
  width: 16px;
  height: 16px;
  padding: 0;
  accent-color: var(--accent);
}

input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}

input[readonly],
.readonly-input {
  color: #5f6f78;
  background: #edf2f4;
  border-color: #ccd6da;
  cursor: not-allowed;
}

input[readonly]:focus,
.readonly-input:focus {
  border-color: #ccd6da;
  box-shadow: none;
}

button {
  height: 34px;
  padding: 0 14px;
  border: 1px solid var(--accent);
  border-radius: 5px;
  color: #ffffff;
  background: var(--accent);
  cursor: pointer;
}

button:hover {
  background: var(--accent-strong);
}

button:disabled {
  color: #8b949e;
  background: #eef2f4;
  border-color: #cfd8dc;
  cursor: not-allowed;
}

button.secondary {
  color: var(--accent-strong);
  background: #ffffff;
}

button.secondary:hover {
  background: var(--surface-soft);
}

button.danger {
  color: var(--danger);
  background: var(--danger-bg);
  border-color: #ffb4ab;
}

button.danger:hover {
  background: #ffe4e0;
}

button.small {
  height: 30px;
  padding: 0 10px;
  font-size: 13px;
}

.file-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 30px;
  padding: 0 10px;
  color: var(--accent-strong);
  font-size: 13px;
  font-weight: 500;
  background: #ffffff;
  border: 1px solid var(--accent);
  border-radius: 5px;
  cursor: pointer;
}

.file-btn input {
  display: none;
}

.table-wrap {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: visible;
  scrollbar-gutter: stable;
}

table {
  width: 100%;
  min-width: 980px;
  border-collapse: collapse;
  table-layout: fixed;
}

th,
td {
  height: 42px;
  padding: 6px 8px;
  text-align: left;
  vertical-align: middle;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

th {
  color: #263941;
  background: #dff0f4;
  font-size: 12px;
  font-weight: 700;
}

td {
  background: #ffffff;
}

tfoot td {
  color: #263941;
  font-weight: 700;
  background: #f1f7f8;
}

tbody tr:hover td {
  background: #f8fbfb;
}

tbody tr.selected-row td {
  background: #d9eef6;
}

.contract-table table {
  min-width: 1120px;
}

.compact-table table {
  min-width: 860px;
}

#entryPage #unitSection table {
  min-width: 1120px;
}

td input,
td select {
  min-width: 96px;
}

.row-actions {
  display: flex;
  gap: 6px;
}

.icon-btn {
  width: 30px;
  min-width: 30px;
  padding: 0;
}

#reportSection .report-table table {
  min-width: 1800px;
  table-layout: fixed;
}

#reportSection .report-table th:nth-child(1),
#reportSection .report-table td:nth-child(1) {
  width: 38px;
  padding-inline: 6px;
}

#reportSection .report-table th:nth-child(2),
#reportSection .report-table td:nth-child(2),
#reportSection .report-table th:nth-child(3),
#reportSection .report-table td:nth-child(3),
#reportSection .report-table th:nth-child(4),
#reportSection .report-table td:nth-child(4),
#reportSection .report-table th:nth-child(14),
#reportSection .report-table td:nth-child(14) {
  width: 100px;
  white-space: nowrap;
}

#reportSection .report-table th:nth-child(8),
#reportSection .report-table td:nth-child(8),
#reportSection .report-table th:nth-child(9),
#reportSection .report-table td:nth-child(9),
#reportSection .report-table th:nth-child(10),
#reportSection .report-table td:nth-child(10) {
  width: 86px;
  white-space: nowrap;
}

#reportSection .report-table th:nth-child(11),
#reportSection .report-table td:nth-child(11),
#reportSection .report-table th:nth-child(12),
#reportSection .report-table td:nth-child(12) {
  width: 82px;
  white-space: nowrap;
}

#reportSection .report-table th:nth-child(13),
#reportSection .report-table td:nth-child(13) {
  width: 202px;
  white-space: nowrap;
}

#reportSection .report-table th:nth-child(5),
#reportSection .report-table td:nth-child(5) {
  width: 118px;
}

#reportSection .report-table th:nth-child(6),
#reportSection .report-table td:nth-child(6) {
  width: 138px;
}

#reportSection .report-table th:nth-child(7),
#reportSection .report-table td:nth-child(7) {
  width: 146px;
}

#reportSection .report-table th:nth-child(15),
#reportSection .report-table td:nth-child(15) {
  width: 220px;
}

#reportSection .report-table .row-actions {
  gap: 5px;
}

#reportSection .report-table th:nth-child(12),
#reportSection .report-table td:nth-child(12) {
  white-space: normal;
  overflow-wrap: anywhere;
}

.admin-table table {
  min-width: 520px;
}

.check-col {
  width: 42px;
  min-width: 42px;
  text-align: center;
}

.check-col input {
  display: inline-block;
  width: 16px;
  min-width: 16px;
}

.money,
.number {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.summary {
  color: var(--muted);
  font-size: 13px;
}

.admin-summary {
  padding: 14px 16px;
  color: var(--muted);
  font-size: 13px;
}

.detail-split {
  display: grid;
  gap: 16px;
  padding: 14px 0 0;
}

.detail-split h3 {
  margin: 0;
  padding: 0 16px 10px;
  color: #40515b;
  font-size: 14px;
  font-weight: 700;
}

.detail-version {
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.detail-version h3 {
  margin: 0;
  padding: 0 16px 0;
  color: #40515b;
  font-size: 14px;
  font-weight: 700;
}

.change-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  padding: 16px;
}

.change-box {
  display: grid;
  gap: 10px;
  padding: 14px;
  background: #fafcfc;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.change-box h3 {
  margin: 0 0 4px;
  font-size: 14px;
}

.fee-picker {
  display: grid;
  gap: 8px;
  margin-top: 6px;
}

.fee-picker-row {
  display: grid;
  grid-template-columns: minmax(360px, 1fr) 190px 190px 130px;
  gap: 8px;
  align-items: center;
}

.compact-date {
  grid-template-columns: minmax(110px, 1fr) 42px;
}

.check-label {
  display: flex;
  min-height: 34px;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  min-width: 0;
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
}

.check-label input {
  flex: 0 0 auto;
  width: auto;
}

.check-label span {
  overflow: hidden;
  text-overflow: ellipsis;
}

.danger-box {
  background: #fff8f7;
  border-color: #ffd1cc;
}

.version-container {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 14px 16px;
}

.compact-version {
  padding-top: 10px;
}

.empty-card {
  padding: 12px;
  color: var(--muted);
}

.version-detail-table {
  padding: 0 16px 16px;
}

.version-diff-title {
  margin: 2px 0 8px;
  color: #22323b;
  font-size: 13px;
  font-weight: 700;
}

.version-card {
  min-width: 180px;
  padding: 12px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-top: 4px solid var(--accent);
  border-radius: 8px;
}

.version-button {
  height: auto;
  padding: 12px;
  text-align: left;
  color: inherit;
  background: #ffffff;
  cursor: pointer;
}

.version-button:hover,
.active-version {
  border-color: var(--accent);
  background: #ffffff;
  box-shadow: 0 0 0 2px rgba(0, 120, 116, 0.12);
}

.version-change {
  border-top-color: #17643a;
}

.version-supp {
  border-top-color: #6554c0;
}

.version-term {
  border-top-color: var(--danger);
}

.v-title {
  margin-bottom: 6px;
  font-weight: 700;
}

.v-detail {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.ledger-storno td {
  color: var(--danger);
  background: #fff7f5;
}

.ledger-supplement td {
  color: #403294;
  background: #faf8ff;
}

.ledger-partial td {
  background: #fff8df;
}

.inline-money {
  width: 96px;
  height: 28px;
  text-align: right;
}

.ledger-locked td,
.ledger-posted_original td {
  color: #5e6c84;
  background: #f6f8f9;
}

.ledger-credit_note td {
  color: #a45100;
  background: #fffaf0;
}

.ledger-settled_credit td {
  color: #a45100;
  background: #fff7ed;
}

.ledger-settled_rehang td {
  color: #0f5b8f;
  background: #f1f8fc;
}

.modal-backdrop[hidden] {
  display: none;
}

.checkbox-dropdown {
  position: relative;
}

.checkbox-dropdown-toggle {
  display: flex;
  width: 100%;
  height: 34px;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px;
  color: var(--text);
  font-weight: 400;
  background: #ffffff;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
}

.checkbox-dropdown-menu {
  position: absolute;
  z-index: 40;
  top: calc(100% + 4px);
  left: 0;
  width: max(100%, 250px);
  max-height: 260px;
  overflow: auto;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  box-shadow: 0 10px 28px rgb(18 37 45 / 16%);
}

.checkbox-dropdown-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  color: var(--text);
  font-weight: 400;
  cursor: pointer;
}

.checkbox-dropdown-option:hover {
  background: var(--surface-soft);
}

.modal-backdrop {
  position: fixed;
  z-index: 1000;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgb(20 35 45 / 38%);
}

.modal-panel {
  width: min(720px, 100%);
  max-height: min(680px, calc(100vh - 48px));
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 18px 56px rgb(18 37 45 / 24%);
}

.modal-title,
.modal-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
}

.modal-title {
  border-bottom: 1px solid var(--line);
}

.modal-title h2 {
  margin: 0 0 4px;
  font-size: 16px;
}

.modal-title .hint {
  display: block;
}

.credit-selection-list {
  display: grid;
  gap: 8px;
  padding: 14px 16px;
}

.credit-selection-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) 124px;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.credit-selection-info {
  display: grid;
  gap: 3px;
}

.credit-selection-info span {
  color: var(--muted);
  font-size: 12px;
}

.credit-use-input {
  width: 100%;
  text-align: right;
}

.modal-actions {
  justify-content: flex-end;
  border-top: 1px solid var(--line);
}

.writeoff-modal {
  width: min(620px, 100%);
}

.writeoff-credit-section {
  border-bottom: 1px solid var(--line);
}

.writeoff-credit-section h3 {
  margin: 14px 16px 2px;
  font-size: 14px;
}

.writeoff-credit-section .hint {
  margin: 0 16px;
}

.writeoff-credit-section .credit-selection-list {
  max-height: 220px;
  overflow-y: auto;
}

.writeoff-amount-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  align-items: end;
  padding-bottom: 2px;
}

.writeoff-amount-summary span {
  color: var(--muted);
  font-size: 12px;
}

.writeoff-amount-summary strong {
  display: block;
  color: var(--text);
  font-size: 16px;
  line-height: 1.6;
}

.writeoff-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  padding: 18px 16px;
}

.writeoff-form label[hidden] {
  display: none;
}

.ledger-historical_reversal_credit td {
  color: #a45100;
  background: #fff7ed;
}

.ledger-historical_reversal_rehang td {
  color: #0f5b8f;
  background: #f1f8fc;
}

.ledger-void td {
  color: #8b949e;
  background: #f4f5f7;
  text-decoration: line-through;
}

.report-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 12px;
}

.status-select {
  min-width: 88px;
  font-weight: 700;
}

.status-text {
  font-weight: 700;
}

.status-pending {
  color: #8a5a00;
}

.status-partial {
  color: #8a5a00;
}

.status-cleared {
  color: #17643a;
}

.nowrap-actions {
  flex-wrap: nowrap;
  min-width: 226px;
}

button.tiny {
  height: 28px;
  padding: 0 7px;
  font-size: 12px;
  white-space: nowrap;
}

.report-filter-grid {
  border-top: 1px solid var(--line);
  background: #fbfdfd;
}

.empty-row {
  height: 72px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 900px) {
  body {
    min-width: 0;
  }

  .app-header,
  .layout {
    min-width: 0;
  }

  .app-header {
    position: static;
    align-items: flex-start;
    height: auto;
    flex-direction: column;
  }

  .layout {
    display: block;
    padding: 10px;
  }

  .side-nav {
    position: static;
    flex-direction: row;
    height: auto;
    margin-bottom: 12px;
    overflow: auto;
  }

  .nav-btn {
    min-width: 96px;
    text-align: center;
  }

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

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

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

  .report-actions {
    align-items: flex-end;
    flex-direction: column;
  }

}
