:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-soft: #eef6f3;
  --ink: #18211f;
  --muted: #64716d;
  --line: #d9e0dd;
  --accent: #0f766e;
  --accent-strong: #0b5f59;
  --warn: #c2410c;
  --gold: #b7791f;
  --shadow: 0 14px 34px rgba(24, 33, 31, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
}

body {
  min-height: 100%;
  margin: 0;
}

button,
input,
select {
  font: inherit;
  letter-spacing: 0;
}

button {
  min-height: 40px;
  border: 1px solid var(--accent);
  border-radius: 7px;
  background: var(--accent);
  color: #ffffff;
  cursor: pointer;
  font-weight: 700;
  padding: 0 14px;
}

button:hover {
  background: var(--accent-strong);
}

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

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

button.secondary:hover {
  background: var(--surface-soft);
}

button.danger {
  background: #ffffff;
  border-color: #f1b7a7;
  color: var(--warn);
}

button.danger:hover {
  background: #fff1ed;
}

.small-button {
  min-height: 32px;
  padding: 0 10px;
}

input,
select {
  min-height: 40px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #ffffff;
  color: var(--ink);
  padding: 0 11px;
}

input:focus,
select:focus {
  border-color: var(--accent);
  outline: 2px solid rgba(15, 118, 110, 0.14);
}

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

a {
  color: var(--accent);
}

.button-link,
.link-button {
  align-items: center;
  border-radius: 7px;
  display: inline-flex;
  font-weight: 800;
  min-height: 38px;
  text-decoration: none;
}

.button-link {
  background: var(--accent);
  border: 1px solid var(--accent);
  color: #ffffff;
  padding: 0 14px;
}

.link-button {
  color: var(--accent);
}

.app {
  min-height: 100vh;
}

.shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 44px;
}

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

.brand {
  color: var(--accent);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: clamp(28px, 4vw, 44px);
  line-height: 1.05;
  margin-top: 8px;
}

h2 {
  font-size: 20px;
  line-height: 1.2;
}

h3 {
  font-size: 15px;
  line-height: 1.25;
}

.subtitle {
  color: var(--muted);
  line-height: 1.65;
  margin-top: 12px;
  max-width: 680px;
}

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

.panel.flat {
  box-shadow: none;
}

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

.grid {
  display: grid;
  gap: 16px;
}

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

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

.create-layout {
  align-items: start;
  display: grid;
  gap: 22px;
  grid-template-columns: minmax(0, 0.95fr) minmax(320px, 0.7fr);
}

.create-layout.simple-create {
  grid-template-columns: minmax(280px, 480px);
}

.form-row {
  align-items: end;
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr auto;
}

.stack {
  display: grid;
  gap: 12px;
}

.meta-grid {
  display: grid;
  gap: 10px;
}

.link-box {
  align-items: center;
  background: #f7faf9;
  border: 1px solid var(--line);
  border-radius: 7px;
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(0, 1fr) auto;
  padding: 10px;
}

.link-box code {
  color: var(--ink);
  overflow-wrap: anywhere;
}

.message {
  border-radius: 7px;
  font-weight: 700;
  margin-bottom: 14px;
  padding: 11px 12px;
}

.message.ok {
  background: #e8f7f0;
  color: #166534;
}

.message.error {
  background: #fff1ed;
  color: var(--warn);
}

.editor-layout {
  display: grid;
  gap: 18px;
  grid-template-columns: 320px minmax(0, 1fr);
}

.side-column,
.main-column {
  display: grid;
  gap: 18px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  background: var(--surface-soft);
  border: 1px solid #cfe2dc;
  border-radius: 999px;
  color: #17443f;
  display: inline-flex;
  font-size: 13px;
  font-weight: 800;
  line-height: 1;
  padding: 8px 10px;
}

.list {
  display: grid;
  gap: 9px;
}

.list-item {
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 4px;
  padding: 0 0 10px;
}

.list-item:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 13px;
  line-height: 1.45;
}

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

.check-row {
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  display: flex;
  gap: 8px;
  min-height: 40px;
  padding: 0 10px;
}

.check-row input {
  min-height: auto;
  width: auto;
}

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

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

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

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

tr:last-child td {
  border-bottom: 0;
}

.amount {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

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

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

.metric .label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.metric .value {
  font-size: 24px;
  font-weight: 900;
  margin-top: 6px;
}

.metric.receive .value {
  color: var(--accent);
}

.metric.pay .value {
  color: var(--warn);
}

.result-band {
  background: #10201d;
  border-radius: 8px;
  color: #ffffff;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  padding: 16px;
}

.result-band p {
  color: #c9d9d4;
  margin-top: 4px;
}

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

.transfer-item {
  align-items: center;
  background: #f9fbfa;
  border: 1px solid var(--line);
  border-radius: 7px;
  display: flex;
  gap: 10px;
  justify-content: space-between;
  padding: 11px 12px;
}

.pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  display: inline-flex;
  font-size: 12px;
  font-weight: 900;
  padding: 5px 8px;
}

.empty {
  background: #f9fbfa;
  border: 1px dashed #cbd5d1;
  border-radius: 8px;
  color: var(--muted);
  padding: 16px;
}

.loading {
  align-items: center;
  color: var(--muted);
  display: flex;
  min-height: 100vh;
  justify-content: center;
}

.ledger-shell {
  width: min(1280px, calc(100% - 32px));
}

.ledger-header {
  border-bottom: 1px solid var(--line);
  margin-bottom: 16px;
  padding-bottom: 16px;
}

.ledger-header h1 {
  font-size: clamp(28px, 3vw, 38px);
}

.ledger-title-block {
  min-width: min(100%, 680px);
}

.trip-settings {
  align-items: end;
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(220px, 1fr) 180px auto;
  margin-top: 10px;
}

.header-actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.ledger-friends {
  align-items: end;
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(260px, 360px) minmax(0, 1fr);
  margin-bottom: 14px;
}

.friend-inline {
  align-items: end;
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(0, 1fr) auto;
}

.chips.compact {
  align-items: center;
  min-height: 40px;
}

.empty.slim {
  align-items: center;
  display: flex;
  min-height: 40px;
  padding: 9px 12px;
}

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

.metric-strip .metric {
  box-shadow: none;
  padding: 12px;
}

.metric-strip .metric .value {
  font-size: 22px;
}

.ledger-panel {
  box-shadow: none;
  margin-bottom: 14px;
}

.ledger-table {
  min-width: 860px;
}

.ledger-table th:nth-child(1),
.ledger-table td:nth-child(1) {
  width: 88px;
}

.ledger-table th:nth-child(3),
.ledger-table td:nth-child(3) {
  width: 140px;
}

.ledger-table th:nth-child(4),
.ledger-table td:nth-child(4) {
  width: 140px;
}

.ledger-table th:nth-child(5),
.ledger-table td:nth-child(5) {
  width: 130px;
}

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

.ledger-entry-form {
  align-items: end;
  border-top: 1px solid var(--line);
  display: grid;
  gap: 10px;
  grid-template-columns: 130px minmax(180px, 1.2fr) 120px 150px 150px minmax(240px, 1.5fr) auto;
  margin-top: 12px;
  padding-top: 12px;
}

.participant-field {
  display: grid;
  gap: 6px;
}

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

.participant-box {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 40px;
}

.participant-box .check-row {
  min-height: 34px;
  padding: 0 9px;
}

.participant-box .all-row {
  background: var(--surface-soft);
  border-color: #cfe2dc;
  color: #17443f;
  font-weight: 800;
}

.settlement-layout {
  align-items: start;
  display: grid;
  gap: 14px;
  grid-template-columns: minmax(0, 1.15fr) minmax(320px, 0.85fr);
}

.settlement-layout.single {
  grid-template-columns: minmax(0, 0.9fr) minmax(320px, 1.1fr);
}

.view-stack {
  display: grid;
  gap: 16px;
}

.tab-nav {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  overflow-x: auto;
}

.tab-link {
  border-bottom: 3px solid transparent;
  color: var(--muted);
  font-weight: 900;
  min-width: max-content;
  padding: 12px 14px 10px;
  text-decoration: none;
}

.tab-link.active {
  border-bottom-color: var(--accent);
  color: var(--accent);
}

.stats-grid {
  align-items: start;
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-bottom: 14px;
}

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

.stat-row {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 12px;
  justify-content: space-between;
  padding: 0 0 8px;
}

.stat-row:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.rate-panel {
  box-shadow: none;
  margin-bottom: 14px;
}

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

.rate-form {
  align-items: center;
  background: #fff8ed;
  border: 1px solid #f2d5ad;
  border-radius: 8px;
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(170px, 1fr) 150px auto auto;
  padding: 10px;
}

.rate-form.missing {
  background: #fff1ed;
  border-color: #f1b7a7;
}

.rate-form input[type="number"] {
  min-width: 0;
}

.warn-text {
  color: var(--warn);
  font-weight: 800;
}

@media (max-width: 900px) {
  .create-layout,
  .editor-layout,
  .grid.two,
  .grid.three,
  .summary-grid,
  .ledger-friends,
  .metric-strip,
  .settlement-layout,
  .settlement-layout.single,
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .topbar,
  .result-band {
    display: grid;
  }

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

  .header-actions {
    justify-content: stretch;
  }

  .header-actions button {
    width: 100%;
  }

  .trip-settings,
  .ledger-entry-form,
  .rate-form {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .shell {
    width: min(100% - 20px, 1180px);
    padding-top: 18px;
  }

  .panel {
    padding: 14px;
  }

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

  .link-box {
    grid-template-columns: 1fr;
  }
}
