:root {
  color-scheme: light;
  --bg: #f5f7fa;
  --panel: #ffffff;
  --text: #1f2937;
  --muted: #64748b;
  --border: #dbe2ea;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --success: #16803c;
  --warning: #9a6700;
  --danger: #b42318;
  --soft-blue: #eaf1ff;
  --soft-green: #eaf7ef;
  --soft-amber: #fff4d6;
  --shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-family: "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 28px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(10px);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 22px;
  font-weight: 700;
}

h2 {
  font-size: 17px;
}

#health,
.section-title span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.top-actions,
.form-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

button {
  min-height: 36px;
  padding: 0 14px;
  border: 0;
  border-radius: 6px;
  background: var(--primary);
  color: #ffffff;
  font-weight: 700;
  cursor: pointer;
}

button:hover {
  background: var(--primary-dark);
}

button.secondary {
  border: 1px solid var(--border);
  background: #ffffff;
  color: var(--text);
}

button.secondary:hover {
  background: #f1f5f9;
}

button.danger {
  background: var(--danger);
}

a.text-link {
  color: var(--primary);
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
}

a.text-link:hover {
  text-decoration: underline;
}

.link-button {
  min-height: auto;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--danger);
  font-weight: 700;
}

.link-button:hover {
  background: transparent;
  color: #7a271a;
  text-decoration: underline;
}

.layout {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 22px 28px 36px;
}

.ledger-layout {
  width: min(1680px, 100%);
}

.apply-body {
  background: #f7f9fc;
}

.apply-topbar {
  position: static;
}

.apply-layout {
  width: min(960px, 100%);
  margin: 0 auto;
  padding: 22px 18px 40px;
}

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(135deg, #edf4fb 0%, #f8fbfd 52%, #eef8f1 100%);
}

.login-shell {
  width: min(900px, 100%);
  min-height: 460px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  overflow: hidden;
  border: 1px solid #d6e0eb;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 22px 56px rgba(31, 41, 55, 0.12);
}

.login-visual {
  display: grid;
  align-content: center;
  gap: 24px;
  padding: 42px 48px;
  border-right: 1px solid #dbe7f3;
  background: #f2f7fc;
}

.login-visual img {
  width: 186px;
  height: auto;
}

.login-visual h1 {
  color: #15304f;
  font-size: 30px;
  line-height: 1.2;
}

.login-visual p {
  max-width: 340px;
  margin-top: 10px;
  color: #52657a;
  font-size: 14px;
  line-height: 1.8;
}

.login-card {
  display: grid;
  align-content: center;
  gap: 18px;
  padding: 42px 36px;
}

.login-card-head {
  display: grid;
  gap: 8px;
}

.login-card-head span {
  color: var(--primary);
  font-size: 13px;
  font-weight: 800;
}

.login-card-head h2 {
  color: #172033;
  font-size: 24px;
}

.login-form {
  display: grid;
  gap: 15px;
}

.login-form input {
  min-height: 42px;
}

.login-form button {
  min-height: 42px;
  margin-top: 4px;
}

.login-error {
  padding: 10px 12px;
  border: 1px solid #fecaca;
  border-radius: 6px;
  background: #fff5f5;
  color: var(--danger);
  font-size: 13px;
  font-weight: 700;
}

.logout-link {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #ffffff;
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
}

.logout-link:hover {
  background: #f1f5f9;
}

.grid {
  display: grid;
  gap: 18px;
  margin-top: 18px;
}

.grid.two {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

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

.section-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
  background: var(--border);
}

.metrics div {
  min-height: 90px;
  padding: 18px;
  background: #ffffff;
}

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

.metrics strong {
  display: block;
  margin-top: 10px;
  font-size: 28px;
}

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

.apply-form {
  padding-bottom: 20px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
}

input,
select,
textarea {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  color: var(--text);
  background: #ffffff;
  font: inherit;
}

textarea {
  resize: vertical;
}

.wide {
  grid-column: 1 / -1;
}

.people-block {
  display: grid;
  gap: 14px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fbfdff;
}

.allocation-block {
  display: grid;
  gap: 14px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fbfdff;
}

.people-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.people-head h3 {
  margin: 0;
  font-size: 15px;
}

.people-head p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.amount-chip {
  display: grid;
  min-width: 118px;
  gap: 2px;
  padding: 8px 10px;
  border: 1px solid #c7d7fe;
  border-radius: 8px;
  background: #eff6ff;
  text-align: right;
}

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

.amount-chip strong {
  color: var(--primary);
  font-size: 18px;
}

.summary-strip {
  display: grid;
  grid-template-columns: repeat(2, minmax(112px, 1fr));
  gap: 8px;
  min-width: min(292px, 100%);
}

.summary-strip div {
  min-height: 58px;
  padding: 8px 10px;
  border: 1px solid #c7d7fe;
  border-radius: 8px;
  background: #eff6ff;
}

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

.summary-strip strong {
  display: block;
  margin-top: 6px;
  color: var(--primary);
  font-size: 17px;
}

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

.month-group {
  display: grid;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
}

.month-group-head {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.person-add-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

.group-people-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 34px;
}

.person-chip {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  min-height: 30px;
  gap: 8px;
  padding: 4px 8px 4px 10px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  background: #f8fafc;
  color: var(--text);
  font-size: 13px;
}

.person-chip span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.person-chip button {
  width: 22px;
  min-height: 22px;
  padding: 0;
  border-radius: 999px;
  background: #e2e8f0;
  color: var(--text);
  line-height: 1;
}

.person-chip button:hover {
  background: #cbd5e1;
}

.empty-inline {
  display: flex;
  align-items: center;
  min-height: 34px;
  color: var(--muted);
  font-size: 13px;
}

.add-month-btn {
  justify-self: start;
}

.people-table-wrap {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
}

.people-table th,
.people-table td {
  padding: 10px 12px;
}

.empty-cell {
  color: var(--muted);
  text-align: center;
}

.apply-actions {
  justify-content: flex-end;
  grid-column: 1 / -1;
}

.result-panel {
  margin-top: 16px;
  padding: 16px 18px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: var(--shadow);
}

.result-panel.hidden {
  display: none;
}

.result-panel.success {
  border-color: #bbf7d0;
  background: #f0fdf4;
}

.result-panel.error {
  border-color: #fecaca;
  background: #fff5f5;
}

.result-panel.info {
  border-color: #bfdbfe;
  background: #eff6ff;
}

.result-title {
  font-weight: 800;
}

.result-body {
  margin-top: 8px;
  color: var(--text);
  font-size: 14px;
}

.result-body p {
  margin-top: 4px;
}

.result {
  min-height: 92px;
  margin: 12px 20px 20px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #f8fafc;
  white-space: pre-wrap;
  color: var(--text);
  overflow: auto;
}

.codebox {
  display: block;
  width: calc(100% - 40px);
  min-height: 272px;
  margin: 18px 20px 14px;
  font-family: Consolas, "Courier New", monospace;
  font-size: 13px;
}

.panel > .form-actions {
  padding: 0 20px 20px;
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  font-size: 13px;
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-weight: 700;
  background: #f8fafc;
}

.employee-table {
  max-height: 430px;
}

.matrix-table {
  max-height: 540px;
}

.ledger-table {
  max-height: calc(100vh - 170px);
}

.month {
  text-align: center;
  min-width: 68px;
}

.month.available {
  color: #166534;
  background: #ecfdf3;
}

.month.reserved {
  color: #92400e;
  background: #fffbeb;
}

.month.used {
  color: #1d4ed8;
  background: #eff6ff;
}

.month.ineligible {
  color: #64748b;
  background: #f1f5f9;
}

.amount-cell {
  color: var(--success);
  font-weight: 700;
}

.remark-cell {
  min-width: 120px;
  color: var(--muted);
}

.remark {
  color: var(--danger);
}

.list {
  display: grid;
  gap: 12px;
  padding: 16px 20px 20px;
}

.item {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  background: #ffffff;
}

.item-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

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

.item-meta,
.participants {
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.badge.pending,
.badge.reserved,
.badge.submitted {
  color: var(--warning);
  background: var(--soft-amber);
}

.badge.approved {
  color: var(--success);
  background: var(--soft-green);
}

.badge.rejected,
.badge.canceled,
.badge.failed {
  color: var(--danger);
  background: #fee4e2;
}

.item-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

@media (max-width: 900px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
    padding: 16px;
  }

  .layout {
    padding: 16px;
  }

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

  .person-add-row,
  .people-head,
  .month-group-head,
  .summary-strip {
    grid-template-columns: 1fr;
    flex-direction: column;
  }

  .amount-chip {
    width: 100%;
    text-align: left;
  }

  .metrics div {
    min-height: 74px;
  }
}

@media (max-width: 760px) {
  .login-body {
    padding: 16px;
  }

  .login-shell {
    grid-template-columns: 1fr;
  }

  .login-visual {
    gap: 12px;
    padding: 28px 24px;
    border-right: 0;
    border-bottom: 1px solid #dbe7f3;
  }

  .login-visual img {
    width: 132px;
  }

  .login-visual h1 {
    font-size: 24px;
  }

  .login-card {
    padding: 28px 24px 30px;
  }
}
