:root {
  --ink: #17362f;
  --ink-soft: #5e716b;
  --forest: #153f35;
  --forest-2: #1c5d4c;
  --mint: #b9f5d9;
  --mint-soft: #e6f8ef;
  --paper: #f5f7f3;
  --white: #ffffff;
  --line: #dbe4df;
  --coral: #d9684c;
  --shadow: 0 18px 50px rgba(21, 63, 53, 0.12);
  font-family: Inter, ui-rounded, "SF Pro Rounded", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--paper);
  font-synthesis: none;
}

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

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background:
    radial-gradient(circle at 80% -10%, rgba(185, 245, 217, 0.68), transparent 33rem),
    var(--paper);
}

button, input, select { font: inherit; }
button { cursor: pointer; }

.app-shell { width: min(100%, 1120px); margin: 0 auto; padding: 0 24px 48px; }

.topbar {
  height: 82px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  border: 0;
  background: transparent;
  color: var(--forest);
  font-weight: 750;
  font-size: 1.2rem;
  padding: 6px 0;
}

.brand-mark {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 11px 11px 11px 4px;
  background: var(--forest);
  color: var(--mint);
  font-size: 1rem;
}

.app-version { margin-left: auto; margin-right: 14px; color: var(--ink-soft); font-size: .76rem; font-weight: 700; letter-spacing: .04em; }
.invite-banner { display: grid; gap: 4px; max-width: 620px; margin: 0 0 22px; padding: 14px 16px; border: 1px solid #b8dfcd; border-radius: 15px; background: #effaf4; color: var(--forest); }
.invite-banner strong { font-size: .96rem; }
.invite-banner span { color: var(--ink-soft); font-size: .9rem; line-height: 1.4; }
.invite-banner-warning { max-width: none; margin-top: 26px; border-color: #f0cf9e; background: #fff8eb; }
.incoming-invites-panel { display: grid; gap: 12px; margin: 28px 0 8px; padding: 18px; border: 1px solid #b8dfcd; border-radius: 20px; background: #effaf4; }
.incoming-invites-panel h2 { font-size: 1.15rem; }
.incoming-invite-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 12px 14px; border-radius: 14px; background: var(--white); }
.incoming-invite-row p { margin: 0; color: var(--ink-soft); font-size: .9rem; }
.incoming-invite-row strong { color: var(--ink); }

.profile-button, .avatar {
  border: 0;
  background: var(--mint);
  color: var(--forest);
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 750;
}

.profile-button { width: 42px; height: 42px; }
.profile-button.signed-out { width: auto; padding: 0 15px; border-radius: 999px; }

.signed-out-hero { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(340px, .95fr); gap: clamp(34px, 7vw, 92px); align-items: center; min-height: min(680px, calc(100vh - 120px)); padding: 46px 0 72px; }
.welcome-copy h1 { max-width: 640px; font-size: clamp(3rem, 6.5vw, 5.7rem); line-height: .94; margin-bottom: 22px; }
.welcome-copy .intro { max-width: 510px; font-size: clamp(1.05rem, 2vw, 1.2rem); line-height: 1.55; }
.welcome-actions { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 28px; }
.welcome-actions .primary-button, .welcome-actions .secondary-button { min-height: 52px; padding-inline: 22px; }
.welcome-points { display: flex; flex-wrap: wrap; gap: 10px 18px; margin-top: 28px; color: var(--ink-soft); font-size: .86rem; }
.welcome-points span { display: inline-flex; align-items: center; gap: 7px; }
.welcome-points i { display: grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; background: var(--mint); color: var(--forest-2); font-style: normal; font-weight: 850; }
.welcome-preview { position: relative; min-height: 360px; display: grid; place-items: center; }
.preview-glow { position: absolute; width: 330px; height: 330px; border-radius: 50%; background: radial-gradient(circle, rgba(187,246,218,.95), rgba(187,246,218,0) 70%); filter: blur(2px); }
.preview-card { position: relative; width: min(100%, 410px); padding: 28px; border: 1px solid rgba(185,245,217,.22); border-radius: 28px; background: linear-gradient(145deg, #1b5044, #10372f); color: var(--white); box-shadow: 0 26px 70px rgba(21,63,53,.25); transform: rotate(1deg); }
.preview-card::before { content: ""; position: absolute; inset: 10px -9px -9px 9px; z-index: -1; border-radius: 28px; background: rgba(21,63,53,.12); transform: rotate(-2deg); }
.preview-card-head, .preview-footer { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.preview-brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 800; }
.preview-brand b { display: grid; place-items: center; width: 25px; height: 25px; border-radius: 8px 8px 8px 3px; background: var(--mint); color: var(--forest); font-size: .75rem; }
.preview-label { margin: 26px 0 10px; color: var(--mint); font-size: .68rem; font-weight: 850; letter-spacing: .14em; }
.preview-dot { color: var(--mint); font-size: .9rem; }
.preview-card h2 { margin: 30px 0 8px; font-size: 1.8rem; }
.preview-card h2 + p { color: rgba(255,255,255,.72); line-height: 1.5; }
.preview-items { display: grid; gap: 10px; margin: 24px 0; }
.preview-items span { display: flex; align-items: center; gap: 10px; padding: 11px 12px; border: 1px solid rgba(185,245,217,.14); border-radius: 13px; background: rgba(255,255,255,.08); color: var(--white); font-weight: 700; }
.preview-items b { display: grid; place-items: center; width: 29px; height: 29px; border-radius: 9px; background: var(--mint); color: var(--forest); font-size: 1rem; }
.preview-items em { font-style: normal; flex: 1; }
.preview-items i { color: var(--mint); font-style: normal; font-size: 1.3rem; line-height: 1; }
.preview-footer { padding-top: 16px; border-top: 1px solid rgba(185,245,217,.18); color: var(--mint); font-size: .82rem; font-weight: 750; }
.preview-avatars { display: flex; padding-left: 8px; }
.preview-avatars b { display: grid; place-items: center; width: 27px; height: 27px; margin-left: -8px; border: 2px solid var(--white); border-radius: 50%; background: var(--mint); font-size: .7rem; }

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 24px;
  margin: 36px 0 26px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--forest-2);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 8px; font-size: clamp(2rem, 5vw, 3.5rem); letter-spacing: -0.045em; line-height: 1; }
h2 { margin-bottom: 0; font-size: 1.45rem; letter-spacing: -0.025em; }
h3 { font-size: 1rem; }
.intro { color: var(--ink-soft); margin-bottom: 0; font-size: 1rem; }

.primary-button, .secondary-button, .ghost-button {
  min-height: 46px;
  border-radius: 14px;
  padding: 0 18px;
  border: 1px solid transparent;
  font-weight: 750;
}

.primary-button { background: var(--forest); color: var(--white); }
.primary-button:hover { background: var(--forest-2); }
.secondary-button { background: var(--white); color: var(--forest); border-color: var(--line); }
.auth-switch-button { min-height: 42px; border: 0; background: transparent; color: var(--forest-2); padding: 4px 10px; font-weight: 750; text-decoration: underline; text-underline-offset: 3px; }
.auth-switch-button:hover { color: var(--forest); }
.ghost-button { background: transparent; color: var(--forest-2); padding-inline: 10px; }
.full { width: 100%; }
.button-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.danger-button { min-height: 44px; padding: 0 15px; border: 1px solid #e4bdbd; border-radius: 12px; background: #fff8f8; color: #a33c3c; font: inherit; font-weight: 750; cursor: pointer; }
.danger-button:hover { background: #fff0f0; }
.permission-note, .group-meta { color: var(--ink-soft); font-size: .82rem; }
.group-meta { margin-top: 5px; }

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

.group-card {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  border-radius: 24px;
  padding: 24px;
  text-align: left;
  box-shadow: 0 8px 30px rgba(21, 63, 53, 0.05);
  color: var(--ink);
  transition: transform 160ms ease, box-shadow 160ms ease;
}

.group-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.group-card-top { display: flex; justify-content: space-between; gap: 14px; }
.group-card h2 { margin: 0 0 8px; }
.group-card p { color: var(--ink-soft); margin: 0; }
.group-card-total { font-size: 1.35rem; font-weight: 800; white-space: nowrap; }
.group-card-bottom { display: flex; justify-content: space-between; align-items: center; margin-top: 34px; }
.avatar-stack { display: flex; padding-left: 8px; }
.avatar { width: 36px; height: 36px; margin-left: -8px; border: 3px solid var(--white); }
.open-label { color: var(--forest-2); font-weight: 750; }

.empty-state {
  border: 1px dashed #aebeb6;
  border-radius: 24px;
  padding: 48px 24px;
  text-align: center;
  color: var(--ink-soft);
}

.back-button {
  border: 0;
  background: transparent;
  padding: 8px 0;
  color: var(--forest-2);
  font-weight: 750;
}

.group-layout { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(300px, 0.75fr); gap: 22px; }
.panel { background: var(--white); border: 1px solid var(--line); border-radius: 24px; padding: 22px; }
.balance-hero { background: var(--forest); color: var(--white); border: 0; overflow: hidden; position: relative; }
.balance-hero::after { content: ""; position: absolute; width: 150px; height: 150px; border-radius: 50%; right: -38px; top: -58px; background: rgba(185,245,217,.16); }
.balance-hero p { color: rgba(255,255,255,.76); margin-bottom: 6px; }
.balance-hero strong { font-size: clamp(2rem, 6vw, 3.25rem); color: var(--mint); letter-spacing: -0.045em; }
.balance-hero small { display: block; margin-top: 6px; color: rgba(255,255,255,.76); }

.section-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 12px; }
.section-head h2 { font-size: 1.15rem; }
.section-head-actions { display: inline-flex; align-items: center; gap: 12px; }
.compact-button { min-height: 38px; padding: 0 13px; border-radius: 10px; font-size: .88rem; }
.expense-list { display: grid; }
.expense-row { display: grid; width: 100%; grid-template-columns: 46px minmax(0,1fr) auto 18px; gap: 13px; align-items: center; padding: 15px 0; border: 0; border-top: 1px solid var(--line); background: transparent; color: inherit; font: inherit; text-align: left; cursor: pointer; }
.expense-row:hover { background: var(--mint-soft); }
.expense-row:focus-visible { outline: 2px solid var(--forest-2); outline-offset: 2px; border-radius: 6px; }
.expense-copy { overflow-wrap: anywhere; }
.expense-row:first-child { border-top: 0; }
.expense-symbol { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 13px; background: var(--mint-soft); font-size: 1.25rem; }
.expense-copy strong, .expense-money strong { display: block; }
.expense-copy small, .expense-money small { color: var(--ink-soft); font-size: 0.8rem; }
.expense-money { text-align: right; font-variant-numeric: tabular-nums; }
.expense-edit-icon { width: 18px; height: 18px; color: var(--ink-soft); }

.member-list { display: grid; gap: 8px; margin-top: 15px; }
.member-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; }
.member-row .avatar { margin: 0; border: 0; width: 38px; height: 38px; }
.member-row span:nth-child(2) { flex: 1; }
.member-row span:nth-child(2) { display: flex; flex-direction: column; gap: 2px; }
.owner-label { color: var(--ink-soft); font-size: .74rem; font-weight: 600; }
.member-remove { width: 28px; height: 28px; border: 0; border-radius: 50%; background: transparent; color: var(--ink-soft); font-size: 1.25rem; cursor: pointer; }
.member-remove:hover { background: #f2f5f3; color: #a33c3c; }
.balance-number { font-weight: 750; font-variant-numeric: tabular-nums; }
.positive { color: var(--forest-2); }
.negative { color: var(--coral); }

.auth-loading { min-height: calc(100vh - 110px); display: grid; place-content: center; justify-items: center; gap: 14px; color: var(--ink-soft); font-weight: 700; }
.auth-loading-mark { width: 58px; height: 58px; display: grid; place-items: center; border-radius: 18px; background: var(--forest); color: var(--white); font-size: 1.7rem; font-weight: 850; box-shadow: var(--shadow); animation: loading-pulse 1.1s ease-in-out infinite alternate; }
@keyframes loading-pulse { from { opacity: .62; transform: scale(.96); } to { opacity: 1; transform: scale(1); } }

.settlement-list { display: grid; gap: 10px; }
.settlement { background: var(--mint-soft); border-radius: 16px; padding: 14px; display: grid; grid-template-columns: 1fr auto; gap: 8px 12px; align-items: center; }
.settlement p { margin: 0; font-size: .94rem; }
.settlement strong { color: var(--forest); font-variant-numeric: tabular-nums; }
.settlement .settle-button { grid-column: 1 / -1; min-height: 40px; border: 1px solid rgba(21, 63, 53, .2); border-radius: 11px; background: var(--white); color: var(--forest); font-weight: 750; }
.payment-history { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }
.payment-history h3 { margin-bottom: 10px; }
.payment-row { display: flex; justify-content: space-between; gap: 12px; color: var(--ink-soft); font-size: .86rem; padding: 6px 0; }
.pending-invites { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }
.pending-invites h3 { margin-bottom: 8px; }
.invite-row { display: grid; grid-template-columns: 38px minmax(0, 1fr) auto; align-items: center; gap: 10px; padding: 10px 0; }
.invite-row .avatar { margin: 0; border: 0; width: 38px; height: 38px; background: #eef2ef; color: var(--ink-soft); }
.invite-cancel-button { border: 0; background: transparent; color: var(--ink-soft); font: inherit; font-size: .78rem; cursor: pointer; }
.invite-cancel-button:hover { color: #a33c3c; }
.accepted-badge { background: #d9f7e7; color: #176b4d; }
.invite-copy strong, .invite-copy small { display: block; }
.invite-copy small { color: var(--ink-soft); overflow-wrap: anywhere; }
.invite-actions { grid-column: 2 / -1; display: flex; gap: 8px; flex-wrap: wrap; }
.invite-send-button { min-height: 38px; border: 1px solid var(--line); border-radius: 11px; background: var(--white); color: var(--forest-2); padding: 0 11px; font-weight: 750; }
.pending-badge { color: #815322; background: #fff1da; border-radius: 999px; padding: 5px 8px; font-size: .75rem; font-weight: 800; white-space: nowrap; }
.all-even { color: var(--ink-soft); padding: 10px 0; }

.modal {
  width: min(calc(100% - 28px), 540px);
  border: 0;
  border-radius: 26px;
  padding: 0;
  color: var(--ink);
  box-shadow: 0 24px 80px rgba(8, 33, 27, .28);
}
.modal::backdrop { background: rgba(10, 32, 27, .54); backdrop-filter: blur(4px); }
.modal form { padding: 24px; display: grid; gap: 18px; }
.small-modal { width: min(calc(100% - 28px), 420px); }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.icon-button { width: 42px; height: 42px; border-radius: 50%; border: 1px solid var(--line); background: var(--white); color: var(--ink); font-size: 1.5rem; }
label, legend { font-weight: 720; font-size: .9rem; }
input, select { width: 100%; min-height: 48px; margin-top: 7px; border: 1px solid #c9d6cf; border-radius: 13px; padding: 0 13px; color: var(--ink); background: var(--white); font-size: 1rem; }
input:focus, select:focus { outline: 3px solid rgba(28, 93, 76, .18); border-color: var(--forest-2); }
.field-help { display: block; margin-top: 6px; color: var(--ink-soft); font-size: .78rem; font-weight: 500; }
.previous-contacts { display: grid; gap: 8px; }
.field-label { font-weight: 720; font-size: .9rem; }
.contact-choices { display: flex; flex-wrap: wrap; gap: 8px; }
.contact-choice { display: grid; gap: 2px; min-height: 48px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 13px; background: var(--mint-soft); color: var(--forest); text-align: left; }
.contact-choice strong { font-size: .88rem; }
.contact-choice small { color: var(--ink-soft); font-size: .75rem; }
.contact-choice:hover { border-color: var(--forest-2); }
.two-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.money-input { position: relative; }
.money-input input { padding-right: 38px; }
.money-input span { position: absolute; right: 13px; top: 22px; color: var(--ink-soft); }
fieldset { border: 0; padding: 0; margin: 0; }
.form-error { color: #a33232; margin: 0; font-size: .9rem; }
.check-list { margin-top: 8px; border: 1px solid var(--line); border-radius: 15px; overflow: hidden; }
.check-option { display: flex; align-items: center; gap: 11px; min-height: 48px; padding: 0 13px; font-weight: 600; }
.check-option + .check-option { border-top: 1px solid var(--line); }
.check-option input { width: 20px; min-height: 20px; margin: 0; accent-color: var(--forest-2); }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none; background: var(--forest); color: var(--white); padding: 12px 18px; border-radius: 999px; box-shadow: var(--shadow); transition: 180ms ease; z-index: 10; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 760px) {
  .app-shell { padding: 0 16px 34px; }
  .topbar { height: 68px; }
  .signed-out-hero { display: block; min-height: auto; padding: 38px 0 54px; }
  .welcome-copy h1 { max-width: 620px; font-size: clamp(3rem, 9vw, 4.4rem); line-height: .96; letter-spacing: -.045em; }
  .welcome-copy .intro { max-width: 560px; font-size: 1.05rem; }
  .welcome-preview { min-height: 330px; margin-top: 42px; }
  .preview-card { width: min(100%, 470px); }
  .page-head { margin: 26px 0 20px; align-items: flex-start; flex-direction: column; }
  .page-head .primary-button { width: 100%; }
  .incoming-invite-row { align-items: stretch; flex-direction: column; }
  .group-grid, .group-layout { grid-template-columns: 1fr; }
  .group-card { padding: 20px; border-radius: 20px; }
  .group-card-bottom { margin-top: 25px; }
  .group-detail-head { flex-direction: row; align-items: flex-end; }
  .panel { padding: 18px; border-radius: 20px; }
  .balance-hero { grid-row: 1; }
  .right-column { display: contents; }
  .members-panel { grid-row: 4; }
  .settlements-panel { grid-row: 2; }
  .expenses-panel { grid-row: 3; }
}

@media (max-width: 430px) {
  h1 { font-size: 2.15rem; }
  .signed-out-hero { padding: 30px 0 44px; }
  .welcome-copy h1 { font-size: clamp(2.65rem, 13vw, 3.7rem); line-height: .98; }
  .welcome-copy .intro { font-size: 1rem; }
  .welcome-actions { display: grid; grid-template-columns: 1fr; }
  .welcome-actions button { width: 100%; }
  .welcome-points { display: grid; gap: 10px; }
  .welcome-preview { min-height: 320px; margin-top: 30px; }
  .preview-card { padding: 22px; }
  .group-detail-head { flex-direction: column; align-items: flex-start; }
  .group-detail-head .button-row { width: 100%; }
  .group-detail-head .primary-button { flex: 1; }
  .two-fields { grid-template-columns: 1fr; }
  .expense-row { grid-template-columns: 42px minmax(0,1fr) 18px; }
  .expense-money { grid-column: 2; text-align: left; }
  .expense-edit-icon { grid-column: 3; grid-row: 1 / span 2; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
  .auth-loading-mark { animation: none; }
}
