:root {
  --bg: #faf7f2;
  --card-bg: #ffffff;
  --text: #2b2a28;
  --muted: #8a8478;
  --border: #ede7dd;
  --primary: #e8623d;
  --primary-dark: #c94f2e;
  --accent: #12857a;
  --positive: #1f9e6d;
  --negative: #d64545;
  --radius: 14px;
  --nav-height: 60px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

#app {
  max-width: 520px;
  margin: 0 auto;
  padding: 16px 16px calc(var(--nav-height) + 90px);
  min-height: 100vh;
}

h1 {
  font-size: 1.5rem;
  margin: 4px 0 12px;
}
h3 {
  font-size: 1rem;
  margin: 22px 0 8px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 700;
}
p {
  line-height: 1.45;
}
.muted {
  color: var(--muted);
}
.small {
  font-size: 0.82rem;
}
a {
  color: var(--accent);
  text-decoration: none;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 0 8px;
}
.back-link {
  font-weight: 600;
  color: var(--text);
}
.header-avatar img,
.header-avatar div {
  display: block;
}

.avatar {
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.avatar-fallback {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff;
  font-weight: 700;
}

.list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 1px 2px rgba(30, 20, 10, 0.03);
}
a.card {
  color: inherit;
}
.trip-card {
  justify-content: space-between;
}
.trip-card-title {
  font-weight: 700;
  font-size: 1.02rem;
}
.trip-card-main {
  flex: 1;
  min-width: 0;
}
.event-card {
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  position: relative;
}
.event-card .badge {
  position: absolute;
  top: 14px;
  right: 14px;
}

.balance-pill {
  font-weight: 700;
  font-size: 0.88rem;
  padding: 6px 10px;
  border-radius: 999px;
  background: #f1ede4;
  color: var(--muted);
  white-space: nowrap;
}
.balance-pill.positive {
  background: #e4f6ee;
  color: var(--positive);
}
.balance-pill.negative {
  background: #fbeaea;
  color: var(--negative);
}

.badge {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  background: #f1ede4;
  color: var(--muted);
}
.badge-yes {
  background: #e4f6ee;
  color: var(--positive);
}
.badge-no {
  background: #fbeaea;
  color: var(--negative);
}
.badge-maybe {
  background: #fdf1e0;
  color: #b6791c;
}

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

.fab {
  position: fixed;
  bottom: calc(var(--nav-height) + 16px);
  left: 50%;
  transform: translateX(-50%);
  width: calc(100% - 32px);
  max-width: 488px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 14px;
  font-size: 1rem;
  font-weight: 700;
  box-shadow: 0 6px 18px rgba(232, 98, 61, 0.35);
}

.btn {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.btn-primary.active {
  background: var(--primary);
  color: #fff;
}
.btn-block {
  width: 100%;
  display: block;
}
.btn-small {
  padding: 6px 10px;
  font-size: 0.82rem;
}
.icon-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 1rem;
  cursor: pointer;
  padding: 4px 8px;
}

.tab-bar {
  display: flex;
  gap: 6px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 14px;
  overflow-x: auto;
}
.tab-btn {
  border: none;
  background: none;
  padding: 8px 4px;
  font-weight: 600;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  cursor: pointer;
  white-space: nowrap;
}
.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.balance-row,
.settle-row,
.pack-row {
  justify-content: space-between;
}
.small-row {
  justify-content: space-between;
  padding: 10px 14px;
  font-size: 0.88rem;
}
.history-details {
  margin-top: 16px;
}
.history-details summary {
  color: var(--muted);
  font-size: 0.85rem;
  cursor: pointer;
  margin-bottom: 8px;
}

.bank-details {
  background: #f6f3ec;
  border-radius: 10px;
  padding: 10px 14px;
  margin: 12px 0;
}
.bank-row {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}
.bank-row:last-child {
  border-bottom: none;
}

.checkbox-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 240px;
  overflow-y: auto;
  padding: 4px 0;
}
.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
  font-size: 0.92rem;
}
.checkbox-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
}

.avatar-stack {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.avatar-stack-item {
  position: relative;
}
.rsvp-dot {
  position: absolute;
  bottom: -2px;
  right: -2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--bg);
  background: var(--muted);
}
.rsvp-dot.rsvp-yes {
  background: var(--positive);
}
.rsvp-dot.rsvp-no {
  background: var(--negative);
}
.rsvp-dot.rsvp-maybe {
  background: #d99b2b;
}
.rsvp-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.expense-card {
  justify-content: space-between;
  align-items: flex-start;
}
.split-toggle {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}
.hidden {
  display: none !important;
}
.custom-share {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 8px;
}

.inline-form {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}
.inline-form input[name="name"] {
  flex: 1;
}

form label {
  display: block;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 10px;
}
form input,
form select {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 1rem;
  font-family: inherit;
  background: #fff;
  color: var(--text);
}
.row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.form-error {
  color: var(--negative);
  font-size: 0.86rem;
  min-height: 1.2em;
}
.form-note {
  color: var(--positive);
  font-size: 0.86rem;
  min-height: 1.2em;
}

.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 380px;
}
.login-card h1 {
  text-align: center;
  font-size: 1.6rem;
}

.avatar-upload {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 18px;
}

.invite-link-box {
  background: var(--card-bg);
  border: 1px dashed var(--primary);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 12px;
}
.invite-link-text {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.86rem;
  color: var(--primary-dark);
  word-break: break-all;
  margin-bottom: 10px;
}
#copy-invite-btn {
  width: 100%;
}

#bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--nav-height);
  background: #fff;
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 5;
  padding-bottom: env(safe-area-inset-bottom);
}
#bottom-nav.hidden {
  display: none;
}
.nav-btn {
  flex: 1;
  border: none;
  background: none;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.78rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
}
.nav-btn.active {
  color: var(--primary);
}
.nav-icon {
  font-size: 1.25rem;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20, 15, 10, 0.45);
  display: flex;
  align-items: flex-end;
  z-index: 10;
}
.modal-sheet {
  background: var(--bg);
  width: 100%;
  max-height: 88vh;
  overflow-y: auto;
  border-radius: 18px 18px 0 0;
  padding: 20px 18px calc(20px + env(safe-area-inset-bottom));
  margin: 0 auto;
  max-width: 520px;
}
.modal-sheet h2 {
  margin-top: 0;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-height) + 16px);
  transform: translate(-50%, 20px);
  background: var(--text);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.88rem;
  opacity: 0;
  pointer-events: none;
  transition: all 0.2s ease;
  z-index: 20;
  max-width: 90%;
  text-align: center;
}
.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}
.toast.error {
  background: var(--negative);
}

@media (min-width: 600px) {
  body {
    background: #f0ece3;
  }
  #app {
    background: var(--bg);
    margin-top: 20px;
    border-radius: 18px;
    min-height: calc(100vh - 40px);
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.06);
  }
}
