:root {
  color-scheme: light;
  --ink: #082f3a;
  --muted: #5c7d86;
  --paper: #eaf8f8;
  --card: #fbffff;
  --line: #c9e6e8;
  --accent: #ff765f;
  --accent-deep: #df5a46;
  --positive: #087b70;
  --negative: #be4a42;
  --ocean: #0a4f63;
  --lagoon: #0f8d8d;
  --seafoam: #dff7f2;
  --sand: #fff8ea;
  --shadow: 0 18px 44px #0b53631a;
}

* { box-sizing: border-box; }

html { background: #e8f7f8; overflow-x: hidden; }
body {
  margin: 0;
  background:
    radial-gradient(circle at 12% 12%, #b9f1ec 0 .4rem, transparent .45rem),
    radial-gradient(circle at 88% 18%, #d6fbf5 0 .35rem, transparent .4rem),
    radial-gradient(circle at 30% 80%, #ffffff88 0 .3rem, transparent .36rem),
    linear-gradient(160deg, #e9fbfb 0%, #f7fbf4 48%, #eef8ff 100%);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  min-width: 0;
  overflow-x: hidden;
}

button, input, select, textarea { font: inherit; }
button { touch-action: manipulation; }
.hidden { display: none !important; }

.topbar {
  align-items: center;
  background: linear-gradient(135deg, #073544, #0e6877 55%, #15968c);
  box-shadow: 0 8px 30px #0637422a;
  color: white;
  display: flex;
  justify-content: space-between;
  padding: 18px max(22px, calc((100vw - 760px) / 2));
}

.topbar h1, h2, h3, p { margin: 0; }
.topbar h1 { font-size: 23px; letter-spacing: .04em; }
.eyebrow { color: var(--lagoon); font-size: 10px; font-weight: 800; letter-spacing: .16em; opacity: .82; }
.topbar .eyebrow { color: white; }
.status { background: #ffffff14; border: 1px solid #ffffff40; border-radius: 999px; font-size: 12px; padding: 6px 10px; }
.status.online { background: var(--seafoam); border-color: var(--seafoam); color: #07505d; }
.status.offline { background: #b44939; border-color: #b44939; }
.header-actions, .button-row { align-items: center; display: flex; gap: 8px; }
.text-button { background: #ffffff12; border: 1px solid #ffffff26; border-radius: 999px; color: white; cursor: pointer; padding: 7px 10px; }

main { margin: auto; max-width: 760px; padding: 22px 16px 70px; }
.auth-shell { align-items: center; display: flex; min-height: calc(100vh - 78px); }
.auth-card {
  background: linear-gradient(180deg, #ffffffee, #f7fffd);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow);
  margin: auto;
  max-width: 420px;
  overflow: hidden;
  padding: 34px 28px 28px;
  position: relative;
  width: 100%;
}
.auth-card::before {
  background: linear-gradient(90deg, var(--ocean), var(--lagoon), #7bdccb, var(--accent));
  content: "";
  height: 8px;
  inset: 0 0 auto;
  position: absolute;
}
.auth-card h2 { color: #073544; font-family: Georgia, serif; font-size: 34px; margin-top: 6px; }
.auth-footer { color: var(--muted); font-size: 12px; margin-top: 16px; text-align: center; }
.forgot-password { color: var(--muted); font-size: 12px; margin-top: -6px; text-align: center; }
.auth-tabs { background: #edfafa; border: 1px solid #d5eeee; border-radius: 999px; display: flex; gap: 0; margin: 24px 0 18px; padding: 4px; }
.tab { background: transparent; border: 0; border-radius: 999px; color: var(--muted); cursor: pointer; flex: 1; padding: 9px 2px; }
.tab.active { background: white; box-shadow: 0 7px 18px #0b536314; color: var(--ocean); font-weight: 750; }
.book-toolbar { display: flex; gap: 9px; padding: 0 8px; }
.book-toolbar select { flex: 1; }
.desktop-book-actions { display: flex; gap: 9px; }
.hero {
  background:
    linear-gradient(135deg, #ffffff70, #dff7f290),
    radial-gradient(circle at 88% 16%, #8ce5dc66 0 42px, transparent 43px);
  border: 1px solid #d4eeee;
  border-radius: 24px;
  box-shadow: 0 16px 36px #0b53630f;
  margin-bottom: 14px;
  padding: 22px 20px 26px;
}
.hero > p { color: var(--muted); font-size: 14px; }
.hero h2 { color: #073544; font-family: Georgia, serif; font-size: clamp(34px, 8vw, 54px); margin-top: 5px; }
.summary { color: var(--muted); font-size: 13px; margin-top: 12px; }

.panel {
  background: linear-gradient(180deg, #ffffffee, #f8fffd);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
  padding: 18px;
}
.app-panel { scroll-margin-top: 86px; }

.section-title { align-items: center; display: flex; justify-content: space-between; margin-bottom: 14px; }
.section-title h3, .dialog-title h3 { color: #073544; font-family: Georgia, serif; font-size: 23px; }
.primary { background: linear-gradient(135deg, var(--accent), var(--accent-deep)); border: 0; border-radius: 12px; box-shadow: 0 10px 20px #ff765f2d; color: white; cursor: pointer; font-weight: 750; padding: 10px 15px; }
.secondary { background: #f7fffd; border: 1px solid #bddfe3; border-radius: 12px; color: var(--ocean); cursor: pointer; font-weight: 700; padding: 9px 12px; }
.link-button { display: inline-block; text-align: center; text-decoration: none; }
.danger { background: #fff0ec; border: 1px solid #e8aa9d; border-radius: 12px; color: var(--negative); cursor: pointer; font-weight: 750; padding: 10px 15px; }
.compact { font-size: 12px; padding: 7px 9px; }
.full { margin-top: 4px; width: 100%; }

.balance-row, .transaction-row, .settlement-row {
  align-items: center;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  padding: 13px 0;
}
.balance-row:first-child, .transaction-row:first-child, .settlement-row:first-child { border-top: 0; }
.avatar {
  align-items: center;
  background: linear-gradient(135deg, #c6f3ed, #e8fff7);
  border-radius: 50%;
  color: var(--ocean);
  display: inline-flex;
  font-weight: 800;
  height: 38px;
  justify-content: center;
  margin-right: 10px;
  width: 38px;
}
.person { align-items: center; display: flex; }
.person small, .transaction-row small { color: var(--muted); display: block; margin-top: 3px; }
.amount { font-variant-numeric: tabular-nums; font-weight: 800; }
.transaction-button {
  background: transparent;
  border-bottom: 0;
  border-left: 0;
  border-right: 0;
  color: inherit;
  cursor: pointer;
  text-align: left;
  width: 100%;
}
.transaction-button > div { min-width: 0; }
.transaction-button strong, .transaction-button small {
  overflow-wrap: anywhere;
}
.transaction-button:hover { background: #f8f4eb; }
.transaction-filters {
  background: linear-gradient(135deg, #e9fbfb, #f8fff9);
  border: 1px solid #d6eeee;
  border-radius: 13px;
  display: grid;
  gap: 9px;
  grid-template-columns: 2fr 1fr 1fr;
  margin-bottom: 10px;
  padding: 12px;
}
.transaction-filters input, .transaction-filters select {
  min-width: 0;
}
.date-filters {
  display: grid;
  gap: 9px;
  grid-column: 1 / 3;
  grid-template-columns: 1fr 1fr;
}
.date-filters label {
  color: var(--muted);
  font-size: 11px;
  margin: 0;
}
.filter-actions {
  align-items: end;
  display: flex;
  gap: 8px;
}
.filter-actions button { flex: 1; }
.result-summary {
  color: var(--muted);
  font-size: 12px;
  min-height: 18px;
}
.settlement-action { align-items: center; display: flex; gap: 10px; }
.positive { color: var(--positive); }
.negative { color: var(--negative); }
.empty { color: var(--muted); padding: 13px 0; }

dialog {
  background: linear-gradient(180deg, #ffffff, #f7fffd);
  border: 0;
  border-radius: 20px;
  box-shadow: 0 24px 80px #062f3b38;
  color: var(--ink);
  max-width: 460px;
  padding: 0;
  width: calc(100% - 24px);
}
dialog::backdrop { background: #052c36b8; backdrop-filter: blur(5px); }
form { padding: 22px; }
.dialog-title { align-items: center; display: flex; justify-content: space-between; margin-bottom: 18px; }
.icon-button { background: transparent; border: 0; color: var(--muted); cursor: pointer; font-size: 30px; }
label { display: grid; font-size: 13px; font-weight: 750; gap: 6px; margin-bottom: 14px; }
input, select, textarea {
  background: #fbffff;
  border: 1px solid #bddfe3;
  border-radius: 10px;
  color: var(--ink);
  min-height: 44px;
  padding: 9px 11px;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--lagoon);
  box-shadow: 0 0 0 3px #9ee6dc55;
  outline: 0;
}
textarea { resize: vertical; }
fieldset { border: 1px solid var(--line); border-radius: 12px; margin: 0 0 14px; padding: 12px; }
legend { font-size: 13px; font-weight: 750; padding: 0 5px; }
.participants { display: flex; flex-wrap: wrap; gap: 9px; }
.participants label { align-items: center; display: flex; font-weight: 500; margin: 0; }
.participants input { min-height: auto; }
.participants.with-values { display: grid; gap: 8px; }
.allocation-row {
  align-items: center;
  border-bottom: 1px solid #d9eeee;
  display: flex !important;
  justify-content: space-between;
  padding-bottom: 8px;
}
.allocation-row:last-child { border-bottom: 0; padding-bottom: 0; }
.allocation-row > span { align-items: center; display: flex; gap: 7px; }
.allocation-value input { min-height: 38px; width: 110px; }
.allocation-value em { color: var(--muted); font-size: 12px; font-style: normal; min-width: 20px; }
.dialog-actions { display: flex; gap: 10px; justify-content: flex-end; }
.dialog-actions .primary { min-width: 120px; }
.form-message { color: var(--negative); font-size: 13px; min-height: 18px; padding-top: 10px; text-align: center; }
.member-row { border-top: 1px solid var(--line); display: flex; justify-content: space-between; padding: 11px 0; }
.member-row:first-child { border-top: 0; }
.member-row small { color: var(--muted); }
.member-card { border-top: 1px solid var(--line); padding: 12px 0; }
.member-card:first-child { border-top: 0; }
.member-card-main, .member-card-actions { align-items: center; display: flex; gap: 8px; justify-content: space-between; }
.member-card-main small { color: var(--muted); display: block; margin-top: 3px; }
.member-card-actions { margin-top: 9px; }
.member-card-actions select { flex: 1; min-height: 38px; }
.member-list { margin-bottom: 16px; }
.invite-result { color: var(--positive); font-weight: 750; margin-top: 12px; text-align: center; }
.invite-list { border-top: 1px solid var(--line); margin-top: 15px; padding-top: 8px; }
.invite-row { align-items: center; display: flex; justify-content: space-between; padding: 8px 0; }
.invite-row small { color: var(--muted); display: block; font-size: 11px; margin-top: 2px; }
.admin-section { border-top: 1px solid var(--line); margin-top: 18px; padding-top: 14px; }
.admin-section h4 { margin: 0 0 8px; }
.admin-row { align-items: center; border-top: 1px solid var(--line); display: flex; gap: 10px; justify-content: space-between; padding: 10px 0; }
.admin-row:first-child { border-top: 0; }
.admin-row small { color: var(--muted); display: block; font-size: 11px; margin-top: 3px; overflow-wrap: anywhere; }
.admin-row > div { min-width: 0; }
.account-email { color: var(--muted); font-size: 13px; margin: -8px 0 14px; overflow-wrap: anywhere; }
.danger-zone { border-top: 1px solid var(--line); margin-top: 22px; padding-top: 18px; }
.danger-zone p { color: var(--muted); font-size: 12px; margin: 6px 0 10px; }
.receipt-tools { align-items: center; display: flex; justify-content: space-between; margin: -4px 0 14px; }
.receipt-tools a { color: var(--positive); font-size: 13px; font-weight: 750; }
.receipt-tools label { align-items: center; display: flex; font-weight: 500; margin: 0; }
.receipt-tools input { min-height: auto; }
.receipt-status {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
  margin: -8px 0 14px;
}
.export-tools { display: grid; gap: 8px; grid-template-columns: 1fr 1fr; margin-top: 10px; }
.mobile-nav { display: none; }
.action-sheet-content { padding: 20px; }
.action-grid { display: grid; gap: 10px; grid-template-columns: 1fr 1fr; }

@media (max-width: 640px) {
  :root { --mobile-nav-height: 76px; }

  .topbar {
    padding: 12px 15px;
    position: sticky;
    top: 0;
    z-index: 20;
  }
  .topbar .eyebrow { display: none; }
  .topbar h1 { font-size: 20px; }
  .header-actions { gap: 6px; }
  .header-actions .text-button { display: none; }
  .status { font-size: 11px; padding: 5px 8px; }

  main {
    max-width: none;
    padding: 14px 10px calc(var(--mobile-nav-height) + 24px);
    width: 100%;
  }
  .auth-shell {
    min-height: calc(100dvh - 57px);
    padding-bottom: 20px;
  }
  .auth-card {
    border: 0;
    border-radius: 18px;
    padding: 24px 20px;
  }
  .auth-card h2 { font-size: 31px; }

  .book-toolbar {
    padding: 0;
    width: 100%;
  }
  .book-toolbar select {
    font-size: 16px;
    min-width: 0;
    width: 100%;
  }
  .desktop-book-actions { display: none; }
  .hero { padding: 18px 4px 20px; }
  .hero > p { font-size: 13px; }
  .hero h2 {
    font-size: 34px;
    line-height: 1.08;
    overflow-wrap: anywhere;
  }
  .summary { line-height: 1.5; margin-top: 9px; }

  .panel {
    border-radius: 16px;
    margin-bottom: 11px;
    padding: 15px 14px;
  }
  .app-panel { scroll-margin-top: 68px; }
  .section-title { gap: 10px; margin-bottom: 10px; }
  .section-title h3 { font-size: 21px; }
  .section-title .button-row { display: none; }
  .balance-row, .transaction-row, .settlement-row {
    gap: 10px;
    min-width: 0;
    padding: 14px 0;
  }
  .balance-row .amount, .transaction-row .amount {
    flex: 0 0 auto;
    font-size: 14px;
  }
  .person { min-width: 0; }
  .person > div { min-width: 0; }
  .person strong, .person small { overflow-wrap: anywhere; }
  .avatar {
    flex: 0 0 38px;
    margin-right: 9px;
  }
  .transaction-button { align-items: flex-start; }
  .transaction-button > div { flex: 1; }
  .transaction-button small { font-size: 11px; line-height: 1.45; }
  .transaction-filters {
    grid-template-columns: 1fr 1fr;
    margin: 0 -2px 8px;
    padding: 10px;
  }
  .transaction-filters input[name="search"] {
    grid-column: 1 / -1;
  }
  .date-filters {
    grid-column: 1 / -1;
  }
  .filter-actions {
    grid-column: 1 / -1;
  }
  .result-summary { margin-top: 4px; }
  .settlement-row { align-items: flex-start; flex-direction: column; }
  .settlement-action {
    align-items: center;
    flex-direction: row;
    justify-content: space-between;
    width: 100%;
  }
  .settlement-action .secondary { min-height: 40px; }

  input, select, textarea {
    font-size: 16px;
    max-width: 100%;
    min-height: 48px;
    width: 100%;
  }
  button, .secondary, .primary, .danger { min-height: 44px; }

  dialog:not(.action-sheet) {
    border-radius: 0;
    height: 100dvh;
    margin: 0;
    max-height: none;
    max-width: none;
    width: 100%;
  }
  dialog:not(.action-sheet)[open] {
    display: block;
    inset: 0;
    position: fixed;
  }
  dialog:not(.action-sheet) form {
    min-height: 100%;
    padding: 16px 15px calc(30px + env(safe-area-inset-bottom));
  }
  .dialog-title {
    background: var(--card);
    margin: -16px -15px 18px;
    padding: 13px 15px 10px;
    position: sticky;
    top: 0;
    z-index: 2;
  }
  .dialog-title h3 { font-size: 22px; }
  .icon-button {
    align-items: center;
    display: inline-flex;
    font-size: 28px;
    height: 44px;
    justify-content: center;
    min-height: 44px;
    width: 44px;
  }
  fieldset { padding: 12px 10px; }
  .participants { display: grid; gap: 5px; }
  .participants label, .allocation-row {
    min-height: 44px;
    width: 100%;
  }
  .participants input[type="checkbox"] {
    flex: 0 0 auto;
    width: auto;
  }
  .allocation-row { gap: 8px; }
  .allocation-row > span:first-child {
    flex: 1;
    min-width: 0;
    overflow-wrap: normal;
    white-space: nowrap;
  }
  .allocation-value { flex: 0 0 132px; }
  .allocation-value input { min-height: 42px; width: 96px; }
  .dialog-actions {
    background: var(--card);
    bottom: 0;
    margin: 4px -15px -30px;
    padding: 12px 15px calc(12px + env(safe-area-inset-bottom));
    position: sticky;
    z-index: 2;
  }
  .dialog-actions .primary { flex: 1; }
  .member-card-main { align-items: flex-start; }
  .member-card-actions {
    align-items: stretch;
    display: grid;
    grid-template-columns: 1fr auto auto;
  }
  .member-card-actions select { min-width: 0; }
  .invite-row { gap: 8px; }
  .invite-row > div { min-width: 0; }
  .invite-row strong { overflow-wrap: anywhere; }
  .receipt-tools { align-items: flex-start; gap: 10px; }
  .receipt-tools label { width: auto; }
  .receipt-tools input { width: auto; }
  .export-tools { grid-template-columns: 1fr; }

  .mobile-nav {
    align-items: end;
    backdrop-filter: blur(16px);
    background: #f8ffffef;
    border-top: 1px solid var(--line);
    bottom: 0;
    display: grid;
    grid-template-columns: 1fr 1fr 1.15fr 1fr 1fr;
    height: calc(var(--mobile-nav-height) + env(safe-area-inset-bottom));
    left: 0;
    padding: 7px 7px calc(7px + env(safe-area-inset-bottom));
    position: fixed;
    right: 0;
    box-shadow: 0 -12px 30px #08445418;
    z-index: 30;
  }
  .mobile-nav button {
    align-items: center;
    background: transparent;
    border: 0;
    color: var(--muted);
    display: flex;
    font-size: 12px;
    font-weight: 750;
    justify-content: center;
    min-height: 48px;
    padding: 4px;
  }
  .mobile-nav button.active { color: var(--lagoon); }
  .mobile-nav .mobile-add {
    align-self: start;
    background: linear-gradient(135deg, var(--accent), #ff9b72);
    border-radius: 50%;
    box-shadow: 0 10px 24px #ff765f55;
    color: white;
    font-size: 30px;
    height: 56px;
    justify-self: center;
    margin-top: -20px;
    min-height: 56px;
    width: 56px;
  }

  dialog.action-sheet {
    border-radius: 22px 22px 0 0;
    bottom: 0;
    margin: auto 0 0;
    max-width: none;
    width: 100%;
  }
  .action-sheet-content {
    padding: 12px 15px calc(22px + env(safe-area-inset-bottom));
  }
  .action-sheet .dialog-title {
    margin: 0 0 12px;
    padding: 0;
    position: static;
  }
  .action-grid { grid-template-columns: 1fr 1fr; }
}
