:root {
  color-scheme: light;
  --canvas: #f5f7f6;
  --paper: #ffffff;
  --text: #172725;
  --muted: #536762;
  --line: #dce6e2;
  --subtle: #edf3f0;
  --accent: #146459;
  --accent-dark: #104c44;
  --mint: #e3f2eb;
  --amber: #795321;
  --amber-bg: #fbf0dc;
  --red: #a13131;
  --radius: 16px;
  --shadow: 0 14px 40px rgba(18, 60, 50, .055);
  font-family: "PingFang SC", "Noto Sans SC", "Microsoft YaHei", -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  background: var(--canvas);
  color: var(--text);
  font-size: 16px;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; }
[hidden] { display: none !important; }
h1, h2, h3, p, dl, dd { margin: 0; }
a { color: inherit; }
button, input, select, textarea { font: inherit; }
button, a, input, select, textarea { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
button:disabled { cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.muted, .quiet { color: var(--muted); }
.strong { font-weight: 650; }
.sr-only {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.frame { width: min(1260px, calc(100% - 72px)); margin-inline: auto; }
.masthead { background: var(--paper); border-bottom: 1px solid var(--line); }
.masthead-inner { display: flex; align-items: center; justify-content: space-between; min-height: 64px; gap: 12px; }
.brand, .head-actions { display: flex; align-items: center; gap: 12px; }
.brand { min-width: 0; white-space: nowrap; font-size: .98rem; font-weight: 700; }
.brand img { display: block; object-fit: contain; }
.head-actions { gap: 18px; font-size: .875rem; white-space: nowrap; }
.head-link { color: var(--accent-dark); text-decoration: none; font-weight: 650; }
.head-link:hover, .text-button:hover { text-decoration: underline; }
.text-button { border: none; padding: 4px 0; background: transparent; color: var(--muted); }
.demo-tag { color: var(--muted); background: var(--subtle); border-radius: 5px; padding: 3px 6px; font-size: .75rem; font-weight: 550; }

/* The desktop and narrow layouts use the same scrollable ledger. */
.ledger-page {
  --ledger-gutter: clamp(14px, 1.1vw, 24px);
  height: 100dvh;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.ledger-page .masthead-inner { width: 100%; min-height: 55px; padding-inline: var(--ledger-gutter); }
.main-frame, .ledger-sheet { display: flex; flex: 1; flex-direction: column; min-height: 0; min-width: 0; }
.page-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px var(--ledger-gutter) 12px; }
.ledger-title { display: flex; align-items: baseline; gap: 12px; }
.period { color: var(--accent); font-size: .875rem; font-weight: 680; margin-bottom: 7px; }
h1 { font-size: 2rem; line-height: 1.25; font-weight: 720; letter-spacing: -.025em; }
.ledger-title h1 { font-size: 1.52rem; white-space: nowrap; }
.ledger-title .period { margin: 0; white-space: nowrap; }
.roster-total { color: var(--muted); font-size: .875rem; }
.ledger-sheet { background: var(--paper); border-top: 1px solid var(--line); }
.gate-card, .personal-balance, .personal-history { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.ledger-tools { display: flex; align-items: center; gap: 10px; padding: 10px var(--ledger-gutter); }
.ledger-tools > label { min-width: 0; }
.ledger-tools select { max-width: 176px; }
.ledger-tools #add-person { margin-inline-start: auto; }
input, select, textarea {
  color: var(--text);
  background: var(--paper);
  border: 1px solid #becfc8;
  border-radius: 8px;
  min-height: 40px;
  padding: 8px 10px;
  min-width: 0;
  width: 100%;
}
input::placeholder, textarea::placeholder { color: var(--muted); }
input[type="number"] { font-variant-numeric: tabular-nums; }
select {
  appearance: none;
  padding-right: 29px;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 15px) 50%, calc(100% - 10px) 50%;
  background-size: 5px 5px;
  background-repeat: no-repeat;
}
.ledger-tools input, .ledger-tools select { font-size: .875rem; }
.search-field { display: block; position: relative; }
.search-field input { width: clamp(220px, 25vw, 380px); padding-left: 34px; }
.search-field::before {
  content: "";
  position: absolute;
  width: 10px;
  height: 10px;
  border: 1.5px solid var(--muted);
  border-radius: 50%;
  left: 13px;
  top: 13px;
  pointer-events: none;
}
.search-field::after { content: ""; position: absolute; width: 5px; height: 1.5px; background: var(--muted); left: 22px; top: 24px; transform: rotate(46deg); pointer-events: none; }
.table-scroll { flex: 1; width: 100%; min-height: 0; overflow: auto; border-top: 1px solid var(--line); }
.table-scroll:focus-visible { outline-offset: -2px; }
table { width: 100%; border-collapse: separate; border-spacing: 0; text-align: left; font-size: .875rem; }
th { color: var(--muted); background: #eef4f0; font-weight: 650; white-space: nowrap; }
.ledger-table { min-width: 1220px; table-layout: fixed; }
.col-index { width: 62px; }
.col-name { width: 8%; }
.col-dept { width: 11%; }
.col-date { width: 132px; }
.col-years { width: 84px; }
.col-cycle { width: 12%; }
.col-amount { width: 91px; }
.col-operations { width: 168px; }
.ledger-table > thead > tr > th, .ledger-table > tbody > tr > td { padding: 10px 11px; border-bottom: 1px solid var(--subtle); }
.ledger-table > thead > tr > th { position: sticky; z-index: 2; top: 0; border-color: var(--line); }
.ledger-table > :is(thead, tbody) > tr > :is(th, td):first-child { padding-left: var(--ledger-gutter); }
.ledger-table > tbody > tr:hover:not(.details-row), .ledger-table > tbody > .expanded-person { background: #f6faf8; }
.ledger-table .row-operations { position: sticky; right: 0; text-align: right; white-space: nowrap; border-left: 1px solid var(--subtle); }
.ledger-table td.row-operations { z-index: 1; background: var(--paper); }
.ledger-table tr:hover > td.row-operations, .ledger-table .expanded-person > td.row-operations { background: #f6faf8; }
.ledger-table th.row-operations { z-index: 3; }
.applicant { font-weight: 700; overflow-wrap: anywhere; }
.ordinal { color: var(--muted); font-variant-numeric: tabular-nums; }
.number { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.date-cell { color: var(--muted); font-variant-numeric: tabular-nums; }
.note-cell { color: var(--muted); overflow-wrap: anywhere; white-space: pre-line; }
.balance-number { color: var(--accent-dark); font-weight: 740; }
.pending-label { display: inline-block; background: var(--amber-bg); border-radius: 5px; color: var(--amber); padding: 3px 6px; font-size: .8125rem; font-weight: 650; }
.row-action {
  color: var(--accent-dark);
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  padding: 4px 6px;
  font-size: .875rem;
  font-weight: 650;
  white-space: nowrap;
}
.row-action:hover:not(:disabled) { background: var(--mint); }
.row-action + .row-action { margin-inline-start: 2px; }
.row-action.danger { color: var(--red); }
.row-action.danger:hover:not(:disabled) { background: #faeeee; }
.row-action.primary-action { background: var(--accent); color: var(--paper); }
.row-action.primary-action:hover:not(:disabled) { background: var(--accent-dark); }
.row-action:disabled { opacity: .65; }
.ledger-table > tbody > tr > .empty-state { padding: 34px 18px; text-align: center; color: var(--muted); }
.table-footer { display: flex; justify-content: space-between; align-items: center; gap: 8px; border-top: 1px solid var(--line); padding: 8px var(--ledger-gutter); font-size: .8125rem; color: var(--muted); }
.table-footer span:first-child { white-space: nowrap; }
.table-footer span:last-child { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.editing-row, .ledger-table .editing-row:hover:not(.details-row) { background: #edf7f1; }
.ledger-table .editing-row > td { padding-inline: 6px; }
.ledger-table .editing-row > td.row-operations { background: #edf7f1; }
.editing-row input, .editing-row select, .editing-row textarea, .detail-table input, .detail-table select, .bind-field input {
  min-height: 34px;
  padding: 5px 6px;
  font-size: .875rem;
}
.editing-row select { padding-right: 26px; }
.editing-row textarea { display: block; resize: vertical; }
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  min-height: 40px;
  background: var(--paper);
  border: 1px solid #c5d4ce;
  border-radius: 8px;
  font-weight: 650;
  font-size: .9rem;
  padding: 8px 14px;
  text-decoration: none;
  white-space: nowrap;
}
.button:hover:not(:disabled) { background: var(--subtle); }
.button.primary { color: white; border-color: var(--accent); background: var(--accent); }
.button.primary:hover:not(:disabled) { background: var(--accent-dark); border-color: var(--accent-dark); }
.button:disabled { color: var(--muted); border-color: var(--line); background: var(--subtle); font-weight: 550; }
.button.small { min-height: 35px; padding: 5px 10px; font-size: .875rem; }
.gate { display: grid; place-items: start center; padding: clamp(36px, 13vh, 120px) 20px 40px; }
.gate-card { width: min(100%, 402px); padding: 28px; }
.gate-card h1 { font-size: 1.55rem; }
.gate-card .muted { margin-top: 10px; line-height: 1.5; }
.gate-card form { margin-top: 25px; }
.gate-card label { display: block; margin-bottom: 6px; font-size: .875rem; font-weight: 600; }
.gate-action { width: 100%; margin-top: 17px; min-height: 44px; }
.employee-gate form { margin-top: 0; }
.form-error { color: var(--red); font-size: .875rem; margin-top: 8px; }
.notice { background: var(--mint); border: 1px solid #c7e1d5; border-radius: 8px; padding: 9px 12px; color: var(--accent-dark); font-size: .875rem; }
.gate-card .notice { margin-block: 15px 0; }
.toast { position: fixed; bottom: 18px; right: 18px; z-index: 2; box-shadow: var(--shadow); }

.ledger-table > tbody > .details-row > td:first-child { padding: 0; background: #f7faf8; border-bottom: 1px solid var(--line); }
.inline-detail { width: 100%; padding: 13px 0 16px; }
.detail-heading, .binding-view, .detail-hint, .bind-field { padding-inline: var(--ledger-gutter); }
.detail-heading { display: flex; align-items: center; gap: 16px; margin-bottom: 7px; }
.detail-heading h2 { font-size: .95rem; }
.binding-view, .detail-hint { font-size: .8125rem; color: var(--muted); margin: 7px 0; }
.bind-field { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; margin: 8px 0; font-size: .875rem; }
.bind-field input { width: 240px; }
.bind-field [data-binding-result]:not(:empty) { flex-basis: 100%; }
.detail-table { width: 100%; background: var(--paper); border-block: 1px solid var(--line); table-layout: fixed; }
.detail-table :is(td, th) { padding: 8px 10px; border-bottom: 1px solid var(--subtle); overflow-wrap: anywhere; }
.detail-table :is(td, th):first-child { padding-left: var(--ledger-gutter); }
.detail-table tr:last-child td { border-bottom: 0; }
.detail-table th:nth-child(1) { width: 10%; }
.detail-table th:nth-child(2) { width: 12%; }
.detail-table th:nth-child(3), .detail-table th:nth-child(4) { width: max(16%, 210px); }
.detail-table th:nth-child(5) { width: 100px; }
.detail-table th:nth-child(7) { width: 70px; }
.record-time { display: grid; grid-template-columns: minmax(110px, 1fr) 66px; gap: 5px; }
.record-time select { padding-right: 21px; background-position: calc(100% - 10px) 50%, calc(100% - 5px) 50%; }

.personal { width: min(540px, calc(100% - 40px)); margin: 0 auto; padding: 36px 0; }
.personal-heading { margin-bottom: 18px; }
.person-name { display: flex; gap: 7px; flex-wrap: wrap; margin-top: 8px; color: var(--muted); }
.personal-balance { overflow: hidden; }
.balance-hero { color: var(--accent-dark); background: var(--mint); padding: 21px 24px 17px; }
.balance-hero > span { font-size: .9rem; font-weight: 680; }
.balance-hero p { margin-top: 5px; font-size: 1.05rem; }
.balance-hero strong { font-size: 2.9rem; line-height: 1.15; letter-spacing: -.045em; font-variant-numeric: tabular-nums; }
.balance-hero .unknown-balance { font-size: 1.65rem; font-weight: 720; }
.personal-totals { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); padding: 16px 24px; gap: 12px; }
.personal-totals dt, .cycle-line { color: var(--muted); font-size: .875rem; }
.personal-totals dd { margin-top: 4px; font-size: 1.125rem; font-weight: 680; }
.cycle-line { border-top: 1px solid var(--subtle); padding: 10px 24px; }
.cycle-line span { color: var(--text); margin-inline-start: 6px; }
.personal-history { margin-top: 17px; padding: 17px 24px 5px; }
.personal-history h2 { font-size: 1.05rem; }
.history-empty { padding: 15px 0; font-size: .875rem; }
.personal-records { list-style: none; margin: 0; padding: 0; }
.personal-records li { display: flex; justify-content: space-between; align-items: start; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--subtle); font-size: .9rem; line-height: 1.5; }
.personal-records li:last-child { border-bottom: 0; }
.personal-records li div span { font-weight: 680; }
.personal-records time { display: block; color: var(--muted); font-size: .875rem; }
.record-days { white-space: nowrap; font-weight: 680; color: var(--accent-dark); }

@media (max-width: 640px) {
  .frame { width: calc(100% - 28px); }
  .brand, .head-actions { gap: 8px; }
  .brand img { width: 28px; height: 28px; }
  .brand { font-size: .875rem; }
  .head-actions { font-size: .8125rem; white-space: normal; }
  .page-heading { padding-block: 10px; align-items: start; }
  .ledger-title { display: grid; gap: 3px; }
  .ledger-title h1 { font-size: 1.28rem; }
  .ledger-title .period, .roster-total { font-size: .8125rem; }
  .roster-total { text-align: right; }
  .ledger-tools { flex-wrap: wrap; gap: 6px; padding-top: 0; }
  .ledger-tools .search-field { width: 100%; }
  .search-field input { width: 100%; }
  .ledger-tools select { max-width: 115px; }
  .ledger-table .row-operations { position: static; }
  .personal { padding-block: 24px; }
  .personal-heading h1 { font-size: 1.65rem; }
}
