:root {
  --bg: #f7f8f6;
  --surface: #ffffff;
  --line: #dce2dc;
  --text: #1f2a24;
  --muted: #65716a;
  --accent: #1f7a5a;
  --accent-dark: #145a42;
  --amber: #a96316;
  --danger: #b43b3b;
  --shadow: 0 12px 28px rgba(31, 42, 36, 0.08);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

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

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-dark); }

.side-nav {
  position: fixed;
  inset: 0 auto 0 0;
  width: 220px;
  padding: 22px 16px;
  background: #17231d;
  color: #fff;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 4px 22px;
  color: #fff;
}

.nav-brand:hover { color: #fff; }
.nav-brand strong { display: block; font-size: 17px; }
.nav-brand small { display: block; margin-top: 3px; color: #aebbb3; font-size: 12px; }

.brand-mark {
  width: 38px;
  height: 38px;
  display: inline-grid;
  place-items: center;
  border-radius: 8px;
  background: #e9b949;
  color: #17231d;
  font-weight: 800;
}

.nav-link {
  padding: 11px 12px;
  border-radius: 8px;
  color: #d7e0da;
}

.nav-link:hover,
.nav-link.active {
  color: #fff;
  background: rgba(255, 255, 255, 0.1);
}

.app-main {
  margin-left: 220px;
  padding: 26px 30px 42px;
}

.login-main {
  margin-left: 0;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.top-user {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
  color: var(--muted);
}

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 18px;
  margin-bottom: 18px;
}

.head-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0;
}

h1, h2 { margin: 0; letter-spacing: 0; }
h1 { font-size: 30px; }
h2 { font-size: 17px; }

.primary-btn,
.secondary-btn,
.ghost-btn,
button {
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 14px;
  font: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
}

.primary-btn {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 8px 18px rgba(31, 122, 90, 0.18);
}

.primary-btn:hover { background: var(--accent-dark); color: #fff; }
.secondary-btn { background: #eef4ef; color: var(--accent-dark); border-color: #c9d8ce; }
.ghost-btn { background: transparent; color: var(--muted); border-color: var(--line); }
button { background: #eef4ef; color: var(--accent-dark); }

.metric-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.metric-grid.four {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.metric,
.panel,
.login-card,
.expense-form,
.filter-bar {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metric { padding: 16px; }
.metric span { display: block; color: var(--muted); font-size: 13px; }
.metric strong { display: block; margin-top: 8px; font-size: 25px; }

.filter-bar {
  display: grid;
  grid-template-columns: repeat(5, minmax(130px, 1fr)) minmax(220px, 1.4fr) auto auto auto;
  gap: 10px;
  align-items: end;
  padding: 14px;
  margin-bottom: 14px;
}

.filter-bar.settlement {
  grid-template-columns: repeat(5, minmax(130px, 1fr)) minmax(280px, 1.6fr) auto auto auto;
}

.filter-bar.all-data {
  grid-template-columns: repeat(4, minmax(120px, 1fr)) minmax(180px, 1fr) minmax(180px, 1fr) minmax(260px, 1.5fr) auto auto auto;
}

.filter-bar.log-filter {
  grid-template-columns: repeat(2, minmax(150px, 1fr)) minmax(280px, 2fr) auto auto;
}

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

input,
select,
textarea {
  width: 100%;
  border: 1px solid #cfd8d1;
  border-radius: 8px;
  padding: 9px 10px;
  color: var(--text);
  background: #fff;
  font: inherit;
}

select[multiple] {
  min-height: 108px;
  padding: 7px;
}

textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(31, 122, 90, 0.18); border-color: var(--accent); }

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

.wide-panel { grid-row: span 2; }
.panel { padding: 16px; overflow: hidden; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.panel-head span { color: var(--muted); font-size: 12px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 11px 10px; border-bottom: 1px solid #edf0ed; text-align: left; vertical-align: middle; }
th { color: var(--muted); font-weight: 600; background: #fbfcfb; }
th.num, td.num, .num { text-align: right; font-variant-numeric: tabular-nums; }
.strong { font-weight: 700; }
.empty { color: var(--muted); text-align: center; padding: 28px 10px; }
.compact-table td:first-child { color: var(--muted); }
.project-table {
  min-width: 1580px;
  table-layout: fixed;
}
.project-table th,
.project-table td {
  white-space: nowrap;
}
.project-table th:nth-child(1), .project-table td:nth-child(1) { width: 120px; }
.project-table th:nth-child(2), .project-table td:nth-child(2) { width: 110px; }
.project-table th:nth-child(3), .project-table td:nth-child(3) { width: 120px; }
.project-table th:nth-child(4), .project-table td:nth-child(4) { width: 130px; }
.project-table th:nth-child(5), .project-table td:nth-child(5) { width: 90px; }
.project-table th:nth-child(6), .project-table td:nth-child(6) { width: 190px; }
.project-table th:nth-child(7), .project-table td:nth-child(7) { width: 210px; }
.project-table th:nth-child(8), .project-table td:nth-child(8) { width: 90px; }
.project-table th:nth-child(9), .project-table td:nth-child(9) { width: 110px; }
.project-table th:nth-child(10), .project-table td:nth-child(10) { width: 150px; }
.project-table th:nth-child(11), .project-table td:nth-child(11) { width: 110px; }
.project-table th:nth-child(12), .project-table td:nth-child(12) { width: 150px; }
.project-table th:nth-child(13), .project-table td:nth-child(13) { width: 110px; }
.all-records-table th:nth-child(7),
.all-records-table td:nth-child(7),
.all-records-table th:nth-child(8),
.all-records-table td:nth-child(8) {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.settlement-table { min-width: 1780px; }
.settlement-table th,
.settlement-table td { white-space: nowrap; }
.settlement-table .note-cell {
  min-width: 180px;
  white-space: normal;
}

.status {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 3px 8px;
  border-radius: 8px;
  background: #f3f0e8;
  color: var(--amber);
  font-size: 12px;
}

.status.settled {
  background: #edf8f2;
  color: #176141;
}

.status.unsettled {
  background: #fff4e8;
  color: #a96316;
}

.status.partial {
  background: #edf3ff;
  color: #24508f;
}

.settlement-status {
  display: grid;
  gap: 6px;
  justify-items: start;
}

.settlement-status small {
  color: var(--muted);
  line-height: 1.35;
}

.settlement-toggle { margin: 0; }

.settlement-toggle button,
.settlement-action {
  min-height: 28px;
  padding: 3px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--accent-dark);
  font-size: 12px;
}

.settlement-action {
  display: inline-flex;
  align-items: center;
}

.settle-grid {
  grid-template-columns: minmax(280px, 0.75fr) minmax(420px, 1fr);
}

.detail-list {
  display: grid;
  gap: 10px;
  margin: 0;
}

.detail-list div {
  display: grid;
  grid-template-columns: 86px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
}

.detail-list dt {
  color: var(--muted);
  font-size: 13px;
}

.detail-list dd {
  margin: 0;
  font-weight: 600;
}

.actions {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 4px;
}

.actions form { margin: 0; }
.actions button {
  min-height: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--danger);
}

.expense-form { padding: 18px; }
.form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}
.full { grid-column: 1 / -1; }
.form-subhead {
  padding-top: 8px;
  color: var(--text);
  font-weight: 700;
  border-top: 1px solid #edf0ed;
}
.allocation-mode {
  display: grid;
  grid-template-columns: minmax(260px, 0.75fr) minmax(360px, 1fr);
  gap: 14px;
  align-items: stretch;
  padding: 14px;
  border: 1px solid #d6e1d9;
  border-radius: 8px;
  background: #f8fbf9;
}
.allocation-mode .form-subhead {
  padding-top: 0;
  border-top: 0;
}
.allocation-head {
  display: grid;
  gap: 8px;
  align-content: start;
}
.allocation-head p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}
.allocation-head .field-help {
  margin: 0;
  padding: 9px 10px;
  border-radius: 8px;
  background: #eef6f1;
  color: var(--accent-dark);
}
.allocation-choice-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
label.choice-pill {
  position: relative;
  min-height: 74px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid #cbd8cf;
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease, box-shadow .15s ease;
}
label.choice-pill:hover {
  border-color: #8fb4a0;
  background: #fbfdfb;
}
label.choice-pill:has(input:checked) {
  border-color: var(--accent);
  background: #edf8f2;
  box-shadow: inset 0 0 0 1px rgba(31, 122, 90, 0.1);
}
label.choice-pill input {
  flex: 0 0 auto;
  width: auto;
  margin: 0;
  accent-color: var(--accent);
}
.choice-pill span {
  display: grid;
  gap: 4px;
}
.choice-pill strong {
  color: var(--text);
  font-size: 14px;
}
.choice-pill small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}
.field-label {
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 13px;
}
.company-picker {
  padding: 12px;
  border: 1px solid #dbe4dd;
  border-radius: 8px;
  background: #fff;
}
.company-chip-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
label.company-chip {
  width: auto;
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 11px;
  border: 1px solid #cfd8d1;
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  user-select: none;
}
label.company-chip:hover {
  border-color: #8fb4a0;
}
label.company-chip:has(input:checked) {
  border-color: var(--accent);
  background: #edf8f2;
  color: var(--accent-dark);
  font-weight: 700;
}
label.company-chip input {
  width: auto;
  margin: 0;
  accent-color: var(--accent);
}
label.company-chip:has(input:disabled) {
  opacity: .58;
  cursor: default;
}
.field-help {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}
.form-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 18px;
}
.inline-delete { margin-left: auto; }
.inline-delete button { color: var(--danger); background: #fff4f2; border-color: #f0c6c0; }

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

.settings-form {
  display: grid;
  gap: 12px;
}

.file-chip {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 3px 8px;
  border-radius: 8px;
  background: #edf8f2;
  color: var(--accent-dark);
  white-space: nowrap;
}

.file-preview {
  margin-top: 14px;
  padding: 12px;
  border: 1px dashed #bfd1c5;
  border-radius: 8px;
  color: var(--muted);
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.alert {
  padding: 12px 14px;
  border-radius: 8px;
  margin-bottom: 14px;
  border: 1px solid var(--line);
}
.alert.success { background: #edf8f2; color: #176141; border-color: #bfe0ce; }
.alert.error { background: #fff2f1; color: var(--danger); border-color: #efc6c1; }

.login-card {
  width: min(460px, 100%);
  padding: 26px;
}

.login-title {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 22px;
}

.login-title h1 { font-size: 24px; }
.login-form { display: grid; gap: 14px; }
.login-note { margin: 16px 0 0; color: var(--muted); font-size: 13px; line-height: 1.7; }
.muted-line { color: var(--muted); line-height: 1.8; margin: 0; }

@media (max-width: 1100px) {
  .filter-bar { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filter-bar.all-data, .filter-bar.log-filter { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filter-bar.settlement { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .content-grid { grid-template-columns: 1fr; }
  .settle-grid { grid-template-columns: 1fr; }
  .settings-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .allocation-mode { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .side-nav {
    position: static;
    width: auto;
    min-height: 0;
    flex-direction: row;
    align-items: center;
    overflow-x: auto;
  }
  .nav-brand { padding: 0 8px 0 0; }
  .nav-link { flex: 0 0 auto; }
  .app-main { margin-left: 0; padding: 18px 14px 30px; }
  .page-head { align-items: stretch; flex-direction: column; }
  .metric-grid, .form-grid, .filter-bar, .filter-bar.settlement, .filter-bar.all-data, .filter-bar.log-filter { grid-template-columns: 1fr; }
  .allocation-choice-row { grid-template-columns: 1fr; }
  .company-chip-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  label.company-chip { justify-content: flex-start; }
  .head-actions { justify-content: stretch; }
  .head-actions a { flex: 1 1 auto; }
  h1 { font-size: 25px; }
}
