:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-soft: #eef3f7;
  --text: #17202a;
  --muted: #64707d;
  --line: #dbe1e7;
  --blue: #2563eb;
  --green: #0f8b5f;
  --amber: #a16005;
  --red: #b42318;
  --shadow: 0 14px 32px rgba(24, 35, 48, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "SF Pro Display", "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
}

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

button {
  cursor: pointer;
}

a {
  color: inherit;
}

svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: 0 0 auto;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px clamp(16px, 4vw, 34px);
  background: rgba(255, 255, 255, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

.brand,
.top-actions,
.toolbar,
.tabs {
  display: flex;
  align-items: center;
}

.brand {
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  color: #0b5b7a;
  background: #e6f4f1;
  border: 1px solid #c7e3dc;
  border-radius: 8px;
}

.brand h1,
.brand p,
.metric-card strong,
.metric-card span,
.metric-card small,
.report-grid h2 {
  margin: 0;
}

.brand h1 {
  font-size: 20px;
  font-weight: 760;
}

.brand p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
}

.top-actions {
  gap: 10px;
}

.icon-button,
.primary-button,
.ghost-button,
.tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: var(--surface);
}

.icon-button {
  width: 38px;
  padding: 0;
}

.primary-button {
  padding: 0 14px;
  border-color: #174fb8;
  color: #fff;
  background: var(--blue);
}

.ghost-button {
  padding: 0 12px;
}

main {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 22px clamp(14px, 4vw, 34px) 40px;
}

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

.metric-card {
  min-height: 112px;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 4px solid var(--blue);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metric-card span,
.metric-card small {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.metric-card strong {
  display: block;
  margin: 12px 0 8px;
  font-size: 27px;
  line-height: 1.05;
}

.tone-amber {
  border-left-color: var(--amber);
}

.tone-red {
  border-left-color: var(--red);
}

.tone-green {
  border-left-color: var(--green);
}

.workspace {
  margin-top: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.tabs {
  gap: 6px;
  padding: 12px 12px 0;
  border-bottom: 1px solid var(--line);
}

.tab {
  height: 40px;
  padding: 0 14px;
  border-bottom-color: transparent;
  border-radius: 8px 8px 0 0;
  color: var(--muted);
  background: transparent;
}

.tab.active {
  color: var(--blue);
  background: #eef4ff;
  border-color: #c9d8ff;
}

.toolbar {
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.search-field {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 260px;
  height: 40px;
  padding: 0 12px;
  color: var(--muted);
  background: var(--surface-soft);
  border: 1px solid transparent;
  border-radius: 8px;
}

.search-field input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
}

select,
input,
textarea {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}

.toolbar select {
  height: 40px;
  padding: 0 10px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  min-width: 1320px;
  border-collapse: collapse;
}

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

th {
  color: var(--muted);
  background: #fafbfc;
  font-size: 12px;
  font-weight: 700;
}

td {
  font-size: 14px;
}

tbody tr {
  transition: background 0.15s ease;
}

tbody tr:hover {
  background: #f7faff;
}

.amount {
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.repayment-cell {
  display: grid;
  gap: 2px;
  justify-items: end;
  line-height: 1.25;
}

.repayment-cell strong {
  color: var(--text);
  font-weight: 760;
}

.repayment-cell small {
  color: var(--muted);
  font-size: 12px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-width: 62px;
  height: 24px;
  justify-content: center;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  background: #e9f7ef;
  color: var(--green);
}

.status-pill.pending {
  background: #fff5dc;
  color: var(--amber);
}

.status-pill.overdue {
  background: #ffebe9;
  color: var(--red);
}

.status-pill.settled,
.status-pill.paid {
  background: #e9f7ef;
  color: var(--green);
}

.status-pill.archived {
  background: #eceff3;
  color: #59636f;
}

.mobile-list {
  display: none;
  padding: 12px;
  gap: 10px;
}

.mobile-item {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.mobile-item h3 {
  margin: 0 0 8px;
  font-size: 15px;
}

.mobile-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.report-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(320px, 0.9fr);
  gap: 18px;
  padding: 18px;
}

.report-grid h2 {
  margin-bottom: 12px;
  font-size: 16px;
}

.bar-list,
.detail-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.bar-row,
.detail-row {
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
}

.bar-row:last-child,
.detail-row:last-child {
  border-bottom: 0;
}

.bar-row header,
.detail-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.bar-track {
  height: 8px;
  margin-top: 10px;
  background: #eef1f4;
  border-radius: 999px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  background: #0f8b5f;
}

dialog {
  width: min(760px, calc(100vw - 24px));
  border: 0;
  border-radius: 8px;
  box-shadow: 0 24px 60px rgba(16, 24, 40, 0.22);
  padding: 0;
}

dialog::backdrop {
  background: rgba(20, 29, 40, 0.4);
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

.dialog-head h2 {
  margin: 0;
  font-size: 18px;
}

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

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

.form-grid input,
.form-grid select,
.form-grid textarea {
  min-width: 0;
  padding: 10px;
  color: var(--text);
  font-weight: 500;
}

.repayment-inputs {
  display: grid;
  gap: 10px;
  padding: 12px;
  background: #fafbfc;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.section-label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

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

.repayment-preview {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 40px;
  padding: 0 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-variant-numeric: tabular-nums;
}

.repayment-preview span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.span-2 {
  grid-column: span 2;
}

.form-error {
  min-height: 20px;
  margin: 0;
  padding: 0 18px;
  color: var(--red);
  font-size: 13px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 18px 18px;
}

.login-body {
  min-height: 100vh;
  background: linear-gradient(135deg, #eef3f7 0%, #f8fbfb 50%, #eef7f2 100%);
}

.login-shell {
  display: grid;
  width: 100%;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

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

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

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

.feishu-login-button {
  width: 100%;
  text-decoration: none;
}

.login-divider {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
  margin: 16px 0;
  color: var(--muted);
  font-size: 12px;
}

.login-divider::before,
.login-divider::after {
  content: "";
  height: 1px;
  background: var(--line);
}

.login-form label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.login-form input {
  height: 42px;
  padding: 0 12px;
  color: var(--text);
  font-weight: 560;
}

.login-form .primary-button {
  width: 100%;
}

@media (max-width: 980px) {
  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

@media (max-width: 720px) {
  .topbar {
    align-items: flex-start;
  }

  .brand h1 {
    font-size: 18px;
  }

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

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

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

  .search-field {
    min-width: 0;
    width: 100%;
  }

  .tabs {
    overflow-x: auto;
  }

  .table-wrap {
    display: none;
  }

  .mobile-list {
    display: grid;
  }

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

  .split-fields {
    grid-template-columns: 1fr;
  }

  .span-2 {
    grid-column: span 1;
  }
}
