:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --panel: #ffffff;
  --ink: #1d2522;
  --muted: #66736d;
  --line: #dfe5df;
  --primary: #176b5b;
  --primary-dark: #0f4c41;
  --accent: #c99a2e;
  --danger: #b42318;
  --success-bg: #eaf7f0;
  --error-bg: #fff0ed;
  --shadow: 0 18px 50px rgba(22, 37, 33, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
  letter-spacing: 0;
}

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

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

[hidden] {
  display: none !important;
}

.login-view {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(23, 107, 91, 0.1), rgba(201, 154, 46, 0.1)),
    var(--bg);
}

.login-panel {
  width: min(420px, 100%);
  display: grid;
  gap: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px;
  box-shadow: var(--shadow);
}

.login-brand {
  margin-bottom: 6px;
}

.login-notice {
  margin-bottom: 0;
}

.login-submit {
  width: 100%;
  margin-top: 4px;
}

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

.sidebar {
  background: #17211e;
  color: #f8faf7;
  padding: 28px 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 34px;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  color: #17211e;
  font-weight: 800;
}

.brand strong,
.brand span {
  display: block;
}

.brand span {
  color: #b7c2bc;
  font-size: 12px;
  margin-top: 2px;
}

.nav-list {
  display: grid;
  gap: 8px;
}

.nav-item {
  width: 100%;
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #c9d4cf;
  text-align: left;
  padding: 0 14px;
}

.nav-item.active {
  background: #24312d;
  color: #ffffff;
  box-shadow: inset 3px 0 0 var(--accent);
}

.main-panel {
  min-width: 0;
  padding: 26px 28px 36px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 22px;
}

.top-company-metrics {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 28px;
}

.top-company-metrics span {
  min-height: 46px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--muted);
  padding: 0 16px;
  font-size: 15px;
  font-weight: 700;
}

.top-company-metrics strong {
  color: var(--primary-dark);
  overflow-wrap: anywhere;
  font-size: 20px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--primary);
  font-size: 12px;
  font-weight: 700;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 30px;
}

h2 {
  margin-bottom: 4px;
  font-size: 20px;
}

.user-session {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.user-session .secondary-button {
  white-space: nowrap;
}

label {
  display: grid;
  gap: 7px;
  color: #3b4742;
  font-size: 13px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  padding: 10px 11px;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(23, 107, 91, 0.14);
}

input[readonly] {
  background: #f3f6f3;
  color: var(--muted);
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.view-panel {
  display: block;
}

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

.metric span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 8px;
}

.metric strong {
  display: block;
  overflow-wrap: anywhere;
  font-size: 25px;
}

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

.toolbar {
  padding: 16px;
  margin-bottom: 18px;
}

.date-shortcuts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.date-shortcuts .secondary-button {
  min-height: 30px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 400;
}

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

#filterForm {
  display: flex;
  align-items: end;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 2px;
}

#filterForm label {
  min-width: 132px;
  max-width: 160px;
  flex: 0 0 auto;
}

#filterForm input,
#filterForm select {
  min-height: 34px;
  padding: 7px 9px;
}

#filterForm .form-actions {
  flex: 0 0 auto;
}

.user-filter-form {
  grid-template-columns: repeat(4, minmax(150px, 1fr));
}

.form-actions {
  display: flex;
  align-items: end;
  gap: 8px;
}

.primary-button,
.secondary-button,
.icon-button,
.text-button,
.danger-button {
  min-height: 40px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 0 14px;
  font-weight: 700;
}

.primary-button {
  background: var(--primary);
  color: #ffffff;
}

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

.secondary-button {
  background: #f8faf7;
  border-color: var(--line);
  color: var(--ink);
}

.icon-button {
  width: 40px;
  padding: 0;
  background: #f8faf7;
  border-color: var(--line);
  color: var(--ink);
  font-size: 18px;
}

.text-button {
  min-height: 32px;
  background: transparent;
  color: var(--primary);
  padding: 0 8px;
}

.danger-button {
  min-height: 32px;
  background: transparent;
  color: var(--danger);
  padding: 0 8px;
}

.content-band {
  padding: 16px;
}

.full-form-band {
  min-height: calc(100vh - 150px);
}

.page-form {
  max-width: 980px;
}

.page-form-grid {
  margin-top: 18px;
}

.page-form-actions {
  justify-content: flex-start;
}

#createBookView .section-head {
  justify-content: flex-start;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
}

.section-head p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 13px;
}

.notice {
  border-radius: 8px;
  margin-bottom: 12px;
  padding: 11px 12px;
  color: var(--primary-dark);
  background: var(--success-bg);
}

.notice.error {
  color: var(--danger);
  background: var(--error-bg);
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  min-width: 1120px;
  border-collapse: collapse;
  background: #ffffff;
}

.user-table {
  min-width: 760px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 12px 10px;
  text-align: left;
  vertical-align: top;
  font-size: 13px;
}

th {
  position: sticky;
  top: 0;
  background: #f3f6f3;
  color: #4a5651;
  font-size: 12px;
  z-index: 1;
}

td {
  color: #28332f;
}

tbody tr:hover {
  background: #fbfcfa;
}

.amount-cell {
  display: grid;
  gap: 3px;
  white-space: nowrap;
}

.tag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 46px;
  height: 24px;
  border-radius: 999px;
  background: #eef5f2;
  color: var(--primary-dark);
  font-size: 12px;
  font-weight: 700;
}

.tag.expense {
  background: #fff2ef;
  color: var(--danger);
}

.row-actions {
  display: flex;
  gap: 4px;
  white-space: nowrap;
}

.empty-cell {
  height: 140px;
  text-align: center;
  color: var(--muted);
  vertical-align: middle;
}

.pagination {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 12px;
  margin-top: 14px;
}

#pageInfo {
  min-width: 76px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

dialog {
  width: min(760px, calc(100vw - 28px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: 0 24px 90px rgba(20, 28, 25, 0.22);
}

dialog::backdrop {
  background: rgba(23, 33, 30, 0.42);
}

#bookForm {
  padding: 20px;
}

.dialog-head,
.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.dialog-head {
  margin-bottom: 16px;
}

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

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

.dialog-actions {
  justify-content: flex-end;
  margin-top: 18px;
}

#createBookView .page-form-actions {
  justify-content: flex-start;
}

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

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

  .sidebar {
    display: none;
  }

  .main-panel {
    padding: 18px 14px 28px;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .user-session {
    justify-content: flex-start;
  }

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

  #filterForm {
    display: flex;
  }
}

@media (max-width: 640px) {
  h1 {
    font-size: 25px;
  }

  .section-head,
  .dialog-actions {
    align-items: stretch;
    flex-direction: column;
  }

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