:root {
  --bg: #f5f5f7;
  --card: #ffffff;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --border: #d2d2d7;
  --border-soft: #e8e8ed;
  --accent: #007aff;
  --accent-soft: #eef5ff;
  --danger: #ff3b30;
  --danger-soft: #fff0ef;
  --success: #248a3d;
  --success-soft: #edf8ef;
  --shadow: 0 6px 24px rgba(0,0,0,0.07);
  --shadow-hover: 0 10px 30px rgba(0,0,0,0.10);
  --radius: 18px;
  --small-radius: 12px;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  border-radius: var(--small-radius);
  padding: 12px 16px;
  cursor: pointer;
  font-weight: 650;
  transition: transform .12s ease, opacity .12s ease, box-shadow .12s ease;
}

button:active {
  transform: scale(.985);
}

button:disabled {
  cursor: not-allowed;
  opacity: .55;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"] {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--small-radius);
  padding: 12px 13px;
  min-height: 46px;
  background: #fff;
  color: var(--text);
  font-size: 16px;
  outline: none;
  transition: border-color .12s ease, box-shadow .12s ease;
}

input::placeholder {
  color: #9b9ba1;
}

input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0,122,255,.12);
}

.primary {
  background: var(--accent);
  color: #fff;
}

.primary:hover {
  box-shadow: 0 5px 16px rgba(0,122,255,.22);
}

.secondary {
  background: #e9e9ed;
  color: var(--text);
}

.secondary:hover {
  background: #dfdfe4;
}

.ghost {
  background: transparent;
  color: var(--accent);
  padding-left: 8px;
  padding-right: 8px;
}

.danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.full {
  width: 100%;
}

.hidden {
  display: none !important;
}

.app {
  width: min(760px, 100%);
  margin: 0 auto;
  padding: 24px 16px 70px;
}

h1 {
  margin: 8px 0 4px;
  font-size: 32px;
  letter-spacing: -0.7px;
  line-height: 1.08;
}

h2 {
  margin: 0 0 14px;
  font-size: 20px;
  letter-spacing: -.2px;
}

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

.subtitle {
  margin: 0;
  font-size: 15px;
}

.page-header {
  margin-bottom: 24px;
}

.brand-line {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.app-mark {
  width: 46px;
  height: 46px;
  flex: 0 0 46px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: var(--accent);
  color: #fff;
  font-size: 24px;
  font-weight: 800;
  box-shadow: 0 5px 14px rgba(0,122,255,.20);
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 14px;
}

.card-header h2 {
  margin-bottom: 2px;
}

.card-kicker {
  color: var(--muted);
  font-size: 13px;
}

.row {
  display: flex;
  gap: 10px;
  align-items: center;
}

.row.wrap {
  flex-wrap: wrap;
}

.row.between {
  justify-content: space-between;
}

.label {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
  margin: 0 0 6px 2px;
}

.field {
  margin-bottom: 14px;
}

.field:last-child {
  margin-bottom: 0;
}

.field-grid {
  display: grid;
  grid-template-columns: 1.6fr 1fr;
  gap: 10px;
}

.charges {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

/* ---------- Navigation ---------- */
.nav-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--text);
  font-weight: 750;
}

.nav-brand .mini-mark {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 17px;
  font-weight: 800;
}

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

.user-email {
  max-width: 230px;
  padding: 8px 11px;
  border-radius: 999px;
  background: #ececf0;
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- Auth ---------- */
.auth-shell {
  width: min(500px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 36px 16px;
  display: flex;
  align-items: center;
}

.auth-wrap {
  width: 100%;
}

.auth-brand {
  text-align: center;
  margin-bottom: 18px;
}

.auth-brand .app-mark {
  margin: 0 auto 12px;
  width: 56px;
  height: 56px;
  border-radius: 17px;
  font-size: 27px;
}

.auth-brand h1 {
  margin-top: 0;
}

.auth-card {
  width: 100%;
  background: var(--card);
  border-radius: 22px;
  padding: 22px;
  box-shadow: var(--shadow);
}

.auth-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
  padding: 5px;
  margin-bottom: 20px;
  border-radius: 14px;
  background: #ececf0;
}

.auth-switch button {
  padding: 10px 8px;
  background: transparent;
  color: var(--muted);
}

.auth-switch button.active {
  background: #fff;
  color: var(--text);
  box-shadow: 0 1px 5px rgba(0,0,0,.08);
}

.auth-footnote {
  max-width: 390px;
  margin: 14px auto 0;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.message {
  display: none;
  margin: 12px 0 0;
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 14px;
}

.message.visible {
  display: block;
}

.message.error {
  background: var(--danger-soft);
  color: #b42318;
}

.message.success {
  background: var(--success-soft);
  color: #166b2d;
}

.message.info {
  background: var(--accent-soft);
  color: #145aa3;
}

/* ---------- Checks list ---------- */
.new-check-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.new-check-copy strong {
  display: block;
  margin-bottom: 3px;
  font-size: 17px;
}

.new-check-copy span {
  color: var(--muted);
  font-size: 14px;
}

.new-check-card .primary {
  white-space: nowrap;
}

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

.check-row {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 14px;
  border: 1px solid var(--border-soft);
  border-radius: 14px;
  background: #fff;
  transition: border-color .12s ease, transform .12s ease, box-shadow .12s ease;
}

.check-row:hover {
  border-color: #cfd8e6;
  box-shadow: 0 4px 15px rgba(0,0,0,.05);
  transform: translateY(-1px);
}

.check-main {
  cursor: pointer;
  min-width: 0;
}

.check-title {
  font-weight: 750;
  font-size: 17px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.check-meta {
  color: var(--muted);
  font-size: 13px;
  margin-top: 3px;
}

.check-total {
  font-weight: 800;
  margin-top: 5px;
}

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

.empty-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto 10px;
  display: grid;
  place-items: center;
  border-radius: 15px;
  background: #f0f0f3;
  font-size: 23px;
}

/* ---------- Calculator ---------- */
.person-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--accent-soft);
  border: 1px solid #cfe3ff;
  border-radius: 999px;
  padding: 8px 11px;
  font-weight: 650;
}

.chip button {
  background: transparent;
  color: var(--muted);
  padding: 0;
  font-size: 18px;
  line-height: 1;
}

.people-select {
  margin-top: 14px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(90px, 1fr));
  gap: 8px;
}

.person-option {
  position: relative;
}

.person-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.person-option label {
  display: block;
  text-align: center;
  border: 1px solid var(--border);
  border-radius: var(--small-radius);
  padding: 10px 8px;
  cursor: pointer;
  user-select: none;
  font-weight: 650;
  background: #fff;
  transition: background .12s ease, border-color .12s ease, color .12s ease;
}

.person-option input:checked + label {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.item-list {
  margin-top: 16px;
  display: grid;
  gap: 10px;
}

.item {
  border: 1px solid var(--border-soft);
  border-radius: 14px;
  padding: 12px;
}

.item-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
}

.item-name {
  font-weight: 700;
}

.item-meta {
  color: var(--muted);
  font-size: 14px;
  margin-top: 3px;
}

.item-remove {
  background: transparent;
  color: var(--danger);
  padding: 2px 4px;
}

.status {
  margin-top: 10px;
  color: var(--muted);
  font-size: 14px;
}

.status.ok {
  color: var(--success);
}

.calculate-button {
  min-height: 52px;
  font-size: 18px;
  margin-bottom: 16px;
}

.results {
  display: none;
}

.results.visible {
  display: block;
}

.summary-scroll {
  overflow-x: auto;
}

.summary-table {
  width: 100%;
  min-width: 620px;
  border-collapse: collapse;
  margin-top: 10px;
}

.summary-table th,
.summary-table td {
  padding: 10px 6px;
  border-bottom: 1px solid #ededf0;
  text-align: right;
  white-space: nowrap;
}

.summary-table th:first-child,
.summary-table td:first-child {
  text-align: left;
}

.summary-table th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .4px;
}

.total-cell {
  font-weight: 800;
}

.grand-total {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding-top: 16px;
  font-size: 18px;
  font-weight: 700;
}

.grand-total strong {
  font-size: 28px;
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 14px;
}

.save-bar {
  position: sticky;
  bottom: 12px;
  z-index: 5;
  display: flex;
  gap: 10px;
  margin-top: 4px;
  padding: 10px;
  border: 1px solid rgba(210,210,215,.7);
  border-radius: 16px;
  background: rgba(255,255,255,.92);
  box-shadow: 0 8px 30px rgba(0,0,0,.12);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.save-bar button {
  flex: 1;
  min-height: 48px;
}

.helper-note {
  padding: 11px 12px;
  margin-top: 14px;
  border-radius: 12px;
  background: #f7f7f9;
  color: var(--muted);
  font-size: 13px;
}

@media (max-width: 650px) {
  .app {
    padding-top: 18px;
  }

  .field-grid,
  .charges {
    grid-template-columns: 1fr;
  }

  .user-email {
    display: none;
  }

  .new-check-card {
    align-items: stretch;
    flex-direction: column;
  }

  .new-check-card .primary {
    width: 100%;
  }

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

  .auth-shell {
    padding-top: 26px;
    align-items: flex-start;
  }

  .nav-bar {
    align-items: flex-start;
  }

  .nav-actions .secondary {
    padding: 10px 12px;
  }
}
