:root {
  color-scheme: light;
  --bg: #f7f4ee;
  --surface: #fffdf8;
  --surface-strong: #f0eadf;
  --ink: #202124;
  --muted: #6b665e;
  --line: #d8d0c2;
  --accent: #117a6f;
  --accent-strong: #0b5f57;
  --danger: #ad3d31;
  --success: #32703d;
  --warn: #a96216;
  --shadow: 0 18px 50px rgba(34, 31, 25, 0.1);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background:
    linear-gradient(180deg, rgba(17, 122, 111, 0.08), rgba(17, 122, 111, 0) 280px),
    var(--bg);
  color: var(--ink);
}

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

button {
  border: 0;
  cursor: pointer;
}

input,
select,
.total-output {
  min-width: 0;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 10px 11px;
}

.total-output {
  display: block;
  border-style: dashed;
  background: var(--surface-strong);
  color: var(--accent-strong);
  font-weight: 900;
}

.rate-preview {
  margin: -4px 0 0;
  border: 1px solid rgba(17, 122, 111, 0.18);
  border-radius: 6px;
  background: rgba(17, 122, 111, 0.07);
  color: var(--accent-strong);
  padding: 9px 10px;
  font-size: 0.82rem;
  font-weight: 800;
  line-height: 1.35;
}

input:focus,
select:focus {
  border-color: var(--accent);
  outline: 3px solid rgba(17, 122, 111, 0.16);
}

input:disabled,
select:disabled,
button:disabled {
  background: var(--surface-strong);
  color: var(--muted);
  cursor: not-allowed;
}

button:disabled {
  border-color: var(--line);
}

fieldset {
  display: grid;
  gap: 8px;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

legend {
  padding: 0 6px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

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

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

th {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
}

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

.trip-gate {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 460px);
  gap: 24px;
  align-items: center;
  width: min(1040px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 24px;
}

.trip-gate-copy h1 {
  max-width: 620px;
  margin: 0 0 10px;
  font-size: clamp(2rem, 5vw, 4rem);
  line-height: 1.02;
  letter-spacing: 0;
}

.trip-gate-copy .quiet {
  max-width: 540px;
  font-size: 1.02rem;
  line-height: 1.6;
}

.gate-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  max-width: 520px;
  margin-top: 22px;
}

.gate-summary div {
  display: grid;
  gap: 7px;
  border: 1px solid rgba(17, 122, 111, 0.16);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.68);
  padding: 12px;
}

.gate-summary strong {
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 0.86rem;
}

.gate-summary span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 900;
}

.trip-entry-panel {
  display: grid;
  gap: 16px;
}

.return-trip-button {
  justify-self: start;
}

.gate-return-button {
  position: absolute;
  top: 24px;
  left: 24px;
  width: auto;
}

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

.trip-form label {
  display: grid;
  gap: 6px;
}

.trip-form label span {
  font-size: 0.82rem;
  font-weight: 800;
}

.trip-entry-actions {
  display: grid;
  gap: 8px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.trip-entry-saved {
  display: grid;
  gap: 9px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 14px;
}

.trip-entry-saved h3 {
  margin: 0;
  font-size: 0.86rem;
}

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

.saved-trip-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 10px;
  text-align: left;
}

.saved-trip-row:hover:not(:disabled) {
  border-color: rgba(17, 122, 111, 0.42);
  background: rgba(17, 122, 111, 0.08);
}

.saved-trip-row.is-active {
  border-color: rgba(17, 122, 111, 0.28);
  background: rgba(17, 122, 111, 0.07);
}

.saved-trip-row strong,
.saved-trip-row small {
  display: block;
}

.saved-trip-row small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.saved-trip-row em {
  color: var(--accent-strong);
  font-size: 0.78rem;
  font-style: normal;
  font-weight: 900;
  white-space: nowrap;
}

.entry-action {
  display: grid;
  gap: 3px;
  justify-items: start;
  text-align: left;
}

.entry-action strong,
.entry-action small {
  display: block;
}

.entry-action small {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  line-height: 1.35;
}

.invite-preview {
  display: grid;
  gap: 10px;
  border: 1px solid rgba(17, 122, 111, 0.18);
  border-radius: 8px;
  background: rgba(17, 122, 111, 0.07);
  padding: 12px;
}

.invite-lookup-form,
.invite-claim-form {
  display: grid;
  gap: 8px;
}

.invite-preview label {
  display: grid;
  gap: 6px;
}

.invite-preview label span {
  font-size: 0.82rem;
  font-weight: 800;
}

.invite-result {
  display: grid;
  gap: 3px;
  border: 1px solid rgba(17, 122, 111, 0.2);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.72);
  padding: 10px;
}

.invite-result span {
  color: var(--accent-strong);
  font-size: 0.74rem;
  font-weight: 900;
  text-transform: uppercase;
}

.invite-result strong,
.invite-result small {
  overflow-wrap: anywhere;
}

.invite-result small {
  color: var(--muted);
  font-weight: 800;
}

.workspace {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 24px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.84);
  box-shadow: var(--shadow);
  padding: 18px;
}

.topbar h1 {
  margin: 0;
  font-size: clamp(1.7rem, 3vw, 2.4rem);
  letter-spacing: 0;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 0.74rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.quiet,
.field-note,
.item-meta,
.snapshot,
small {
  color: var(--muted);
}

.quiet {
  margin: 0;
}

.grid {
  display: grid;
  grid-template-columns: minmax(330px, 420px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

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

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 8px 28px rgba(34, 31, 25, 0.06);
  padding: 16px;
}

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

.panel-heading h2 {
  margin: 0;
  font-size: 1rem;
}

.panel-heading span {
  border-radius: 999px;
  background: var(--surface-strong);
  color: var(--muted);
  padding: 5px 9px;
  font-size: 0.75rem;
  font-weight: 800;
  white-space: nowrap;
}

.member-list,
.settlement-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.member-row,
.settlement-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 10px;
}

.member-row {
  justify-content: flex-start;
}

.member-row code {
  margin-left: auto;
  max-width: 46%;
  border: 1px solid rgba(17, 122, 111, 0.18);
  border-radius: 6px;
  background: rgba(17, 122, 111, 0.07);
  color: var(--accent-strong);
  padding: 5px 7px;
  font-size: 0.74rem;
  font-weight: 900;
  overflow-wrap: anywhere;
}

.member-row strong,
.member-row small {
  display: block;
}

.final-settlement-panel {
  border-color: rgba(17, 122, 111, 0.26);
  background: linear-gradient(180deg, rgba(17, 122, 111, 0.08), rgba(17, 122, 111, 0.02)), var(--surface);
}

.settlement-help {
  margin: -4px 0 10px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

.final-settlement-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.final-settlement-row {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  border: 1px solid rgba(17, 122, 111, 0.22);
  border-radius: 8px;
  background: #fff;
  padding: 12px;
}

.settlement-step {
  display: grid;
  width: 26px;
  height: 26px;
  place-items: center;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 900;
}

.settlement-route {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: baseline;
  min-width: 0;
}

.settlement-route span {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
}

.settlement-amount {
  color: var(--accent-strong);
  white-space: nowrap;
}

.final-settlement-empty {
  display: grid;
  gap: 4px;
  border: 1px solid rgba(50, 112, 61, 0.22);
  border-radius: 8px;
  background: rgba(50, 112, 61, 0.08);
  color: var(--success);
  padding: 12px;
}

.final-settlement-empty span {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

.member-avatar {
  display: grid;
  flex: 0 0 34px;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 50%;
  background: #d7ebe6;
  color: var(--accent-strong);
  font-weight: 900;
}

.inline-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  margin-top: 12px;
}

.claim-form {
  display: grid;
  gap: 10px;
  margin-top: 14px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.claim-form label {
  display: grid;
  gap: 6px;
}

.claim-form label span {
  font-size: 0.82rem;
  font-weight: 800;
}

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

.expense-form label {
  display: grid;
  gap: 6px;
}

.expense-form label span,
.field-note {
  font-size: 0.82rem;
  font-weight: 800;
}

.form-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.member-money-row,
.participant-row {
  display: grid;
  grid-template-columns: minmax(90px, 1fr) minmax(110px, 150px);
  gap: 10px;
  align-items: center;
}

.participant-row label {
  display: flex;
  grid-template-columns: none;
  align-items: center;
  gap: 8px;
}

.participant-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
}

.primary-button,
.secondary-button,
.inline-form button,
.icon-button {
  border-radius: 6px;
  font-weight: 900;
}

.primary-button {
  background: var(--accent);
  color: #fff;
  padding: 12px 14px;
}

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

.secondary-button,
.inline-form button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  padding: 10px 12px;
}

.action-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 40px;
  white-space: nowrap;
}

.action-button:hover {
  border-color: rgba(17, 122, 111, 0.42);
  background: rgba(17, 122, 111, 0.08);
  color: var(--accent-strong);
}

.button-icon {
  flex: 0 0 17px;
  width: 17px;
  height: 17px;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-button {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font-size: 1.1rem;
  line-height: 1;
}

.notice {
  margin: -6px 0 18px;
  border: 1px solid rgba(50, 112, 61, 0.24);
  border-radius: 8px;
  background: rgba(50, 112, 61, 0.08);
  color: var(--success);
  padding: 10px 12px;
  font-weight: 800;
}

.error {
  margin: 0 0 10px;
  border: 1px solid rgba(173, 61, 49, 0.28);
  border-radius: 8px;
  background: rgba(173, 61, 49, 0.08);
  color: var(--danger);
  padding: 10px;
  font-weight: 800;
}

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

.positive {
  color: var(--success);
  font-weight: 900;
}

.negative {
  color: var(--danger);
  font-weight: 900;
}

.neutral {
  color: var(--muted);
  font-weight: 900;
}

.expense-list {
  display: grid;
  gap: 10px;
}

.expense-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 12px;
}

.item-title {
  margin: 0;
  font-weight: 900;
}

.item-meta,
.snapshot {
  margin: 0;
  font-size: 0.88rem;
}

.snapshot {
  grid-column: 1 / -1;
  overflow-wrap: anywhere;
}

.snapshot span {
  color: var(--ink);
  font-weight: 900;
}

.settings-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: start end;
  background: rgba(32, 33, 36, 0.26);
  padding: 24px;
}

.share-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  background: rgba(32, 33, 36, 0.34);
  padding: 24px;
}

.settings-panel {
  display: grid;
  gap: 16px;
  width: min(380px, 100%);
  max-height: calc(100vh - 48px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 16px;
}

.trip-switcher-panel {
  align-self: start;
}

.share-panel {
  display: grid;
  gap: 14px;
  width: min(560px, 100%);
  max-height: min(820px, calc(100vh - 48px));
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 16px;
}

.settings-panel .panel-heading {
  align-items: start;
  margin-bottom: 0;
}

.share-panel .panel-heading {
  align-items: start;
  margin-bottom: 0;
}

.share-image-frame {
  overflow: auto;
  max-height: 58vh;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  padding: 10px;
}

.share-image-frame img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 6px;
  background: #fff;
}

.share-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.settings-list {
  display: grid;
  gap: 8px;
  margin: 0;
}

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

.settings-list dt {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
}

.settings-list dd {
  margin: 0;
  font-weight: 900;
  text-align: right;
}

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

.settings-summary div {
  display: grid;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 10px;
}

.settings-summary span,
.settings-section h3 {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.settings-summary strong {
  overflow-wrap: anywhere;
  font-size: 0.98rem;
}

.settings-section {
  display: grid;
  gap: 8px;
}

.settings-form {
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

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

.settings-form label span {
  font-size: 0.82rem;
  font-weight: 800;
}

.settings-section h3 {
  margin: 0;
}

.settings-action {
  display: flex;
  width: 100%;
  justify-content: space-between;
  text-align: left;
}

.settings-action span {
  display: grid;
  gap: 3px;
}

.settings-action strong,
.settings-action small {
  display: block;
}

.settings-action small {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
}

.settings-file-input {
  display: none;
}

.danger-zone {
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.danger-button {
  border: 1px solid rgba(173, 61, 49, 0.28);
  border-radius: 6px;
  background: rgba(173, 61, 49, 0.08);
  color: var(--danger);
  padding: 10px 12px;
  font-weight: 900;
}

.danger-button:hover {
  background: rgba(173, 61, 49, 0.14);
}

@media (max-width: 920px) {
  .workspace {
    padding: 14px;
  }

  .trip-gate,
  .topbar,
  .grid,
  .form-pair {
    grid-template-columns: 1fr;
  }

  .trip-gate {
    align-content: center;
    padding-top: 76px;
  }

  .gate-return-button {
    top: 14px;
    left: 14px;
  }

  .topbar {
    display: grid;
  }

  .topbar-actions {
    justify-content: start;
  }
}

@media (max-width: 560px) {
  .panel {
    padding: 12px;
  }

  .gate-summary {
    grid-template-columns: 1fr;
  }

  .inline-form,
  .member-money-row,
  .participant-row,
  .expense-item {
    grid-template-columns: 1fr;
  }

  .secondary-button,
  .inline-form button {
    width: 100%;
  }

  .action-button {
    width: 100%;
  }

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

  .settings-backdrop {
    place-items: end stretch;
    padding: 12px;
  }

  .settings-panel {
    width: 100%;
    max-height: calc(100vh - 24px);
  }

  .share-backdrop {
    place-items: end stretch;
    padding: 12px;
  }

  .share-panel {
    width: 100%;
    max-height: calc(100vh - 24px);
  }

  .share-actions {
    grid-template-columns: 1fr;
  }
}
