:root {
  --bg: #f6f3ef;
  --card: #fff;
  --text: #1c1917;
  --muted: #78716c;
  --accent: #9d174d;
  --accent-soft: #fce7f3;
  --border: #e7e5e4;
  --good: #047857;
  --bad: #b91c1c;
  --warn: #b45309;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  overflow-x: hidden;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 780px) 340px;
  gap: 1.25rem;
  max-width: 1140px;
  margin: 0 auto;
  padding: 1.75rem 1.25rem 3rem;
  align-items: start;
  width: 100%;
}

.layout > * {
  min-width: 0;
  max-width: 100%;
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
    max-width: none;
    padding: 1rem 0.85rem 2.5rem;
    gap: 1rem;
  }

  .sidebar {
    position: static;
    top: auto;
  }

  .pay-left-grid,
  .payment-totals-grid {
    grid-template-columns: 1fr;
  }

  .explain-compare-grid {
    grid-template-columns: 1fr;
  }

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

.shell {
  min-width: 0;
  padding: 0;
}

.sidebar {
  position: sticky;
  top: 1.25rem;
  margin-top: 0;
  min-width: 0;
  max-width: 100%;
}

.sidebar.card {
  overflow: visible;
}

.sidebar-head {
  margin-bottom: 0.85rem;
}

.sidebar-title {
  margin: 0 0 0.2rem;
  font-size: 1.05rem;
}

.sidebar-hint {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.sidebar-blocks {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.sidebar-block {
  padding: 0.7rem 0.75rem;
  background: var(--bg);
  border-radius: 10px;
  border: 1px solid var(--border);
  min-width: 0;
}

.sidebar-block-title {
  margin: 0 0 0.45rem;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.block-hint {
  margin: -0.2rem 0 0.5rem;
  font-size: 0.75rem;
  color: var(--muted);
  line-height: 1.35;
}

.stat-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.45rem;
}

.stat-chip {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.45rem 0.55rem;
}

.stat-chip-inline {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem;
  margin-bottom: 0.45rem;
}

.stat-chip-lbl {
  display: block;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stat-chip-inline .stat-chip-lbl {
  display: inline;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 500;
  font-size: 0.78rem;
}

.stat-chip-val {
  display: block;
  font-size: 1.05rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  margin-top: 0.1rem;
}

.stat-chip-inline .stat-chip-val {
  margin-top: 0;
  font-size: 1rem;
}

.stat-hero {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.45rem;
  padding: 0.6rem 0.7rem;
  border-radius: 8px;
  background: var(--accent-soft);
  border: 1px solid #f9a8d4;
}

.stat-hero.warn {
  background: #fff7ed;
  border-color: #fdba74;
}

.stat-hero.pos {
  background: #ecfdf5;
  border-color: #a7f3d0;
}

.stat-hero-lbl {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
}

.stat-hero-val {
  font-size: 1.35rem;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}

.stat-hero.warn .stat-hero-val {
  color: var(--warn);
}

.stat-hero.pos .stat-hero-val {
  color: var(--good);
}

.sidebar-status {
  margin: 0.5rem 0 0;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.4;
}

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

.sidebar-status.warn {
  color: var(--warn);
}

.pay-left-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.4rem;
}

.pay-left-chip {
  text-align: center;
  padding: 0.45rem 0.35rem;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.pay-left-lbl {
  display: block;
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 0.15rem;
}

.pay-left-val {
  font-size: 0.95rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.pay-left-chip.cash .pay-left-val {
  color: var(--accent);
}

.pay-left-chip.credit .pay-left-val {
  color: #1d4ed8;
}

.pay-left-chip.debit .pay-left-val {
  color: #6d28d9;
}

.pay-left-val.warn {
  color: var(--warn);
}

.pay-left-val.pos {
  color: var(--good);
}

.person-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 0.45rem;
  min-width: 0;
}

.person-card {
  background: var(--bg);
  border-radius: 10px;
  padding: 0.65rem 0.75rem;
  min-width: 0;
}

.person-card-simple {
  padding: 0.55rem 0.5rem;
}

.person-metrics {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 0.3rem;
  margin-bottom: 0.4rem;
  min-width: 0;
}

.person-metric {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.3rem 0.35rem;
  min-width: 0;
}

.person-metric-lbl {
  display: block;
  font-size: 0.6rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.person-metric-val {
  display: block;
  font-size: 0.82rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  margin-top: 0.08rem;
  line-height: 1.2;
}

.person-settlement-line {
  font-size: 0.68rem;
  font-weight: 600;
  line-height: 1.25;
  padding: 0.3rem 0.35rem;
  border-radius: 6px;
  background: #fff;
  border: 1px dashed var(--border);
  text-align: center;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.person-metric-emphasis {
  background: var(--accent-soft);
  border-color: #f9a8d4;
}

.person-settlement-line.warn {
  color: var(--warn);
  border-color: #fdba74;
  background: #fff7ed;
}

.person-settlement-line.pos {
  color: var(--good);
  border-color: #a7f3d0;
  background: #ecfdf5;
}

.final-person-grid {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.final-person-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, auto);
  gap: 0.25rem 0.35rem;
  align-items: center;
  padding: 0.4rem 0.5rem;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.74rem;
  min-width: 0;
}

.final-person-name {
  font-weight: 650;
  color: var(--accent);
  grid-column: 1;
}

.final-person-total {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  grid-column: 1;
  font-size: 0.72rem;
  color: var(--muted);
}

.final-person-vs {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: right;
  grid-column: 2;
  grid-row: 1 / span 2;
  align-self: center;
  font-size: 0.72rem;
  white-space: nowrap;
}

.final-person-vs.pos {
  color: var(--good);
}

.final-person-vs.warn {
  color: var(--warn);
}

.payment-totals-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.4rem;
  margin-bottom: 0.65rem;
}

.sidebar-details {
  padding: 0;
  border: none;
  background: transparent;
}

.sidebar-details-summary {
  list-style: none;
  cursor: pointer;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  padding: 0.7rem 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.sidebar-details-summary::-webkit-details-marker {
  display: none;
}

.sidebar-details[open] .sidebar-details-summary {
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
  border-bottom-color: transparent;
}

.sidebar-details > :not(summary) {
  padding: 0 0.75rem 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 10px 10px;
  margin-top: -1px;
}

.summary-details {
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
}

.summary-details-summary {
  list-style: none;
  cursor: pointer;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  padding: 0.15rem 0 0.55rem;
  user-select: none;
}

.summary-details-summary::-webkit-details-marker {
  display: none;
}

.summary-details-summary::after {
  content: "▾";
  float: right;
  color: var(--accent);
  font-size: 0.85rem;
  transition: transform 0.15s ease;
}

.summary-details[open] .summary-details-summary::after {
  transform: rotate(180deg);
}

.summary-details-body {
  padding-top: 0.1rem;
}

@media (min-width: 641px) {
  .summary-details-summary {
    display: none;
  }
}

.sidebar-stat {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 0.45rem 0;
  border-bottom: 1px solid var(--border);
}

.sidebar-stat.highlight {
  background: var(--accent-soft);
  margin: 0 -0.5rem;
  padding: 0.55rem 0.5rem;
  border-radius: 8px;
  border-bottom: none;
  margin-bottom: 0.75rem;
}

.sidebar-stat.highlight .stat-val {
  color: var(--accent);
  font-size: 1.2rem;
}

.sidebar-stat.due {
  border-bottom: none;
  margin-top: 0.5rem;
  padding-top: 0.65rem;
  border-top: 2px solid var(--border);
}

.sidebar-stat.due .stat-val {
  font-size: 1.25rem;
}

.person-breakdown {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  margin-top: 0.5rem;
  min-width: 0;
}

.person-card .sidebar-stat {
  border-bottom-color: #ddd6d3;
  padding: 0.3rem 0;
}

.person-card .sidebar-stat:last-child {
  border-bottom: none;
}

.person-name {
  margin: 0 0 0.3rem;
  font-size: 0.82rem;
  font-weight: 650;
  color: var(--accent);
  line-height: 1.2;
}

.person-owes .stat-val {
  font-size: 1.1rem;
}

.person-owes .stat-val.warn {
  color: var(--warn);
}

.person-owes .stat-val.pos {
  color: var(--good);
}

.person-owes .stat-val.neg {
  color: var(--bad);
}

.person-items {
  list-style: none;
  margin: 0.5rem 0 0;
  padding: 0.5rem 0 0;
  border-top: 1px dashed var(--border);
}

.person-item {
  padding: 0.35rem 0;
  border-bottom: 1px solid #ebe6e3;
}

.person-item:last-child {
  border-bottom: none;
}

.person-item-name {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: 0.15rem;
}

.person-item-detail {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
  line-height: 1.35;
}

.person-item-detail strong.warn {
  color: var(--warn);
}

.person-item-detail strong.pos {
  color: var(--good);
}

.person-item-detail strong.neg {
  color: var(--bad);
}

.sidebar-msg {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin: 0.5rem 0 0;
  min-height: 1.2rem;
  font-size: 0.82rem;
  color: var(--muted);
}

.sidebar-msg.ok {
  color: var(--good);
}

.sidebar-msg.warn {
  color: var(--warn);
}

.block-msg {
  margin: 0.45rem 0 0;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.35;
}

.block-msg.ok {
  color: var(--good);
}

.block-msg.warn {
  color: var(--warn);
}

.final-settlement-block {
  background: var(--accent-soft);
  border-color: #f9a8d4;
}

.sidebar-block-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.45rem;
}

.sidebar-block-title-row .sidebar-block-title {
  margin-bottom: 0;
}

.help-btn {
  flex-shrink: 0;
  width: 1.65rem;
  height: 1.65rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
  font-family: inherit;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}

.help-btn:hover,
.help-btn[aria-expanded="true"] {
  border-color: var(--accent);
  color: var(--accent);
  background: #fff;
}

.settlement-explain {
  margin-top: 0.55rem;
  padding: 0.65rem 0.7rem;
  border-radius: 8px;
  background: #fff;
  border: 1px solid var(--border);
  font-size: 0.78rem;
  line-height: 1.45;
  color: var(--text);
}

.explain-simple-lead {
  margin: 0 0 0.55rem;
}

.explain-compare-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.45rem;
  margin-bottom: 0.55rem;
}

.explain-compare-card {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding: 0.5rem 0.55rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.explain-compare-name {
  font-weight: 700;
  color: var(--accent);
  font-size: 0.82rem;
  margin-bottom: 0.15rem;
}

.explain-compare-line {
  font-size: 0.74rem;
  color: var(--muted);
}

.explain-compare-total {
  font-size: 0.8rem;
  font-weight: 600;
  margin-top: 0.15rem;
}

.explain-compare-gap {
  font-size: 0.74rem;
  font-weight: 650;
  margin-top: 0.1rem;
}

.explain-compare-gap.warn {
  color: var(--warn);
}

.explain-compare-gap.pos {
  color: var(--good);
}

.explain-simple-result {
  margin: 0 0 0.35rem;
  padding: 0.5rem 0.55rem;
  background: var(--accent-soft);
  border-radius: 6px;
  font-size: 0.8rem;
}

.explain-simple-note {
  margin: 0;
  font-size: 0.72rem;
  color: var(--muted);
}

.settlement-explain-lead {
  margin: 0 0 0.45rem;
}

.settlement-explain-subhead {
  margin: 0.55rem 0 0.35rem;
  font-size: 0.74rem;
}

.settlement-explain-steps,
.settlement-explain-list {
  margin: 0;
  padding-left: 1.15rem;
}

.settlement-explain-steps li,
.settlement-explain-list li {
  margin-bottom: 0.3rem;
}

.settlement-explain-steps li:last-child,
.settlement-explain-list li:last-child {
  margin-bottom: 0;
}

.final-settlement-verdict {
  margin: 0 0 0.55rem;
  padding: 0.55rem 0.65rem;
  border-radius: 8px;
  font-size: 0.84rem;
  line-height: 1.4;
  background: #fff;
  border: 1px solid var(--border);
  color: var(--text);
}

.final-settlement-verdict.highlight {
  border-color: var(--accent);
  color: var(--accent);
}

.final-settlement-verdict.ok {
  background: #ecfdf5;
  border-color: #a7f3d0;
  color: var(--good);
}

.person-metric-val.warn {
  color: var(--warn);
}

.person-metric-val.pos {
  color: var(--good);
}

.cash-pool {
  margin: 0.75rem 0 0.5rem;
  padding: 0.75rem;
  background: var(--bg);
  border-radius: 10px;
  border: 1px solid var(--border);
}

.cash-pool-title {
  margin: 0 0 0.2rem;
  font-size: 0.92rem;
  font-weight: 650;
}

.cash-pool-hint {
  margin: 0 0 0.65rem;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.35;
}

.cash-pool-inputs {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
}

.cash-pool-field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.cash-pool-field input {
  font-size: 1rem;
  font-weight: 600;
  padding: 0.45rem 0.55rem;
  border: 2px solid var(--border);
  border-radius: 8px;
  background: #fff;
  width: 100%;
}

.cash-pool-field input:focus {
  outline: none;
  border-color: var(--accent);
}

.cash-pool-msg {
  margin: 0.5rem 0 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.cash-pool-msg.ok {
  color: var(--good);
}

.cash-pool-msg.warn {
  color: var(--warn);
}

.split-detail {
  margin-top: 0.75rem;
  padding: 0.75rem;
  background: var(--bg);
  border-radius: 10px;
  border: 1px solid var(--border);
}

.split-detail-title {
  margin: 0 0 0.2rem;
  font-size: 0.88rem;
  font-weight: 650;
  color: var(--muted);
}

.split-detail-hint {
  margin: 0 0 0.65rem;
  font-size: 0.75rem;
  color: var(--muted);
  line-height: 1.35;
}

.final-settlement {
  margin-top: 0.75rem;
  padding: 0.75rem;
  background: var(--accent-soft);
  border-radius: 10px;
  border: 1px solid #f9a8d4;
}

.final-settlement-title {
  margin: 0 0 0.2rem;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--accent);
}

.final-settlement-hint {
  margin: 0 0 0.65rem;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.35;
}

.final-settlement-verdict {
  margin: 0.65rem 0 0;
  padding: 0.65rem 0.75rem;
  border-radius: 8px;
  font-size: 0.88rem;
  line-height: 1.4;
  background: #fff;
  border: 1px solid var(--border);
  color: var(--text);
}

.final-settlement-verdict.highlight {
  background: #fff;
  border-color: var(--accent);
  color: var(--accent);
}

.final-settlement-verdict.ok {
  background: #ecfdf5;
  border-color: #a7f3d0;
  color: var(--good);
}

.person-card-final .sidebar-stat.highlight {
  background: rgba(255, 255, 255, 0.65);
  margin: 0 -0.25rem;
  padding: 0.45rem 0.25rem;
  border-radius: 6px;
}

.person-card-simple .sidebar-stat {
  padding: 0.4rem 0;
}

.person-card-simple .person-owes .stat-val {
  font-size: 1.15rem;
}

.person-settlement {
  margin-top: 0.15rem;
  padding-top: 0.5rem;
  border-top: 1px dashed var(--border);
}

.person-settlement .stat-val {
  font-size: 1.05rem;
}

.person-card-detail .sidebar-stat {
  padding: 0.28rem 0;
}

.head h1 {
  font-size: 1.45rem;
  font-weight: 650;
  letter-spacing: -0.02em;
  margin: 0 0 0.35rem;
}

.head-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.head-row .btn {
  flex-shrink: 0;
  margin-top: 0.15rem;
}

.tag {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.budget-picker {
  margin-bottom: 0.65rem;
}

.budget-picker-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: nowrap;
}

.budget-picker-label {
  flex-shrink: 0;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.budget-select {
  flex: 1 1 auto;
  min-width: 9rem;
  max-width: 15rem;
  padding: 0.45rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  font: inherit;
  font-size: 0.92rem;
}

.budget-picker-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
}

.budget-picker-btn {
  width: auto;
  margin: 0;
  padding: 0.45rem 0.75rem;
  font-size: 0.82rem;
  font-weight: 500;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  white-space: nowrap;
}

.budget-picker-btn:hover {
  background: var(--accent-soft);
  border-color: #f9a8d4;
  color: var(--accent);
}

.sync-status {
  display: inline;
  margin: 0;
  padding: 0;
  border: none;
  background: none;
  font: inherit;
  font-size: 0.78rem;
  color: var(--muted);
  text-align: left;
}

.status-row {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  margin-top: 0.35rem;
  flex-wrap: wrap;
}

.last-edited {
  font-size: 0.78rem;
  color: var(--muted);
}

.sync-status.ok {
  color: #2d8a5e;
}

.sync-status.saving {
  color: #b8860b;
}

.sync-status.warn {
  color: #c45c26;
}

.sync-status.retry {
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.sync-status.retry:hover {
  color: #9a3412;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.1rem 1rem;
  margin-top: 1rem;
  box-shadow: 0 6px 24px rgba(28, 25, 23, 0.06);
}

.budget-card .lbl {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 0.4rem;
}

.budget-row {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.currency {
  font-weight: 600;
  font-size: 1.25rem;
  color: var(--muted);
}

#totalBudget {
  flex: 1;
  font-size: 1.5rem;
  font-weight: 600;
  padding: 0.45rem 0.6rem;
  border: 2px solid var(--border);
  border-radius: 10px;
  background: #fafaf9;
}

#totalBudget:focus {
  outline: none;
  border-color: var(--accent);
  background: #fff;
}

.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.35rem;
}

.row-between h2 {
  margin: 0;
  font-size: 1rem;
}

.hint {
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.75rem;
}

.hint code {
  font-size: 0.78rem;
  background: var(--bg);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
}

.lines {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.line-headers,
.line {
  display: grid;
  grid-template-columns: minmax(100px, 1fr) minmax(64px, 76px) minmax(64px, 76px) minmax(80px, 92px) minmax(148px, 158px) minmax(52px, 60px) minmax(72px, 84px) auto;
  gap: 0.3rem;
  align-items: center;
}

.lf {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.lf-label {
  display: none;
}

.lf-row,
.lf-footer {
  display: contents;
}

.lf-name { grid-column: 1; }
.lf-amount { grid-column: 2; }
.lf-deposit { grid-column: 3; }
.lf-paid { grid-column: 4; }
.lf-pay { grid-column: 5; }
.lf-left {
  grid-column: 6;
  display: flex;
  align-items: center;
  justify-content: flex-end;
}
.lf-footer > .line-paid-btn { grid-column: 7; }
.line-remove { grid-column: 8; }

.lf .name,
.lf .amount,
.lf .deposit,
.lf .paid-by {
  width: 100%;
}

.line-headers {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  padding-bottom: 0.15rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.1rem;
}

.line-headers span:nth-child(n + 2):nth-child(-n + 7) {
  text-align: right;
}

.line-headers span:nth-child(5),
.line-headers span:nth-child(7) {
  text-align: center;
}

@media (max-width: 640px) {
  .line-headers {
    display: none;
  }

  .lines {
    gap: 0.55rem;
  }

  .line {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
    padding: 0.7rem;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #fff;
    box-shadow: none;
  }

  .line.line-paid {
    background: #f8fdf9;
    border-color: #d1fae5;
  }

  .lf,
  .lf-row,
  .lf-footer {
    display: flex;
    width: 100%;
  }

  .lf {
    flex-direction: column;
    gap: 0.22rem;
  }

  .lf-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.45rem;
  }

  .lf-label {
    display: block;
    font-size: 0.64rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
  }

  .lf-name {
    padding-right: 2rem;
  }

  .lf-name .name {
    font-size: 0.92rem;
    font-weight: 500;
  }

  .lf-footer {
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding-top: 0.45rem;
    margin-top: 0.05rem;
    border-top: 1px solid var(--border);
  }

  .lf-left {
    flex: 1;
    min-width: 0;
  }

  .line-left {
    font-size: 0.92rem;
    font-weight: 600;
    text-align: left;
  }

  .line-paid .lf-left {
    display: none;
  }

  .line-paid-btn {
    flex-shrink: 0;
    min-height: 2.25rem;
    min-width: 6.25rem;
    padding: 0.35rem 0.75rem;
    font-size: 0.8rem;
    font-weight: 500;
    border-radius: 8px;
  }

  .line-remove {
    position: absolute;
    top: 0.45rem;
    right: 0.45rem;
    width: 1.85rem;
    height: 1.85rem;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 7px;
    font-size: 0.95rem;
    line-height: 1;
  }

  .pay-method {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.35rem;
  }

  .pay-btn {
    min-height: 2.25rem;
    font-size: 0.76rem;
    font-weight: 500;
    border-radius: 8px;
  }

  .line input[type="text"],
  .line select.paid-by {
    font-size: 0.92rem;
    font-weight: 400;
    min-height: 2.25rem;
    padding: 0.4rem 0.55rem;
    border-radius: 8px;
    border-width: 1px;
  }

  .hint {
    display: none;
  }
}

@media (max-width: 640px) {
  .layout {
    padding: 0.65rem 0.6rem 1.75rem;
    gap: 0.75rem;
  }

  .head h1 {
    font-size: 1.05rem;
    font-weight: 600;
    margin-bottom: 0.2rem;
  }

  .tag {
    font-size: 0.82rem;
  }

  .head-row {
    flex-direction: column;
    align-items: stretch;
    gap: 0.55rem;
  }

  .head-row .btn {
    width: 100%;
    margin-top: 0;
    min-height: 2.35rem;
    font-size: 0.84rem;
    font-weight: 500;
  }

  .budget-picker {
    margin-bottom: 0.45rem;
  }

  .budget-picker-row {
    flex-wrap: wrap;
    gap: 0.4rem;
  }

  .budget-picker-label {
    width: 100%;
    font-size: 0.64rem;
  }

  .budget-select {
    flex: 1 1 100%;
    max-width: none;
    min-height: 2.25rem;
    font-size: 0.88rem;
    padding: 0.4rem 0.55rem;
  }

  .budget-picker-actions {
    width: 100%;
    justify-content: stretch;
    gap: 0.35rem;
  }

  .budget-picker-btn {
    flex: 1;
    min-height: 2.25rem;
    font-size: 0.8rem;
    font-weight: 500;
    padding: 0.35rem 0.5rem;
  }

  .card {
    padding: 0.7rem 0.65rem;
    border-radius: 11px;
    margin-top: 0.65rem;
    box-shadow: 0 2px 10px rgba(28, 25, 23, 0.04);
  }

  .row-between {
    flex-direction: column;
    align-items: stretch;
    gap: 0.45rem;
    margin-bottom: 0.25rem;
  }

  .row-between h2 {
    font-size: 0.92rem;
    font-weight: 600;
  }

  .row-between .btn {
    width: 100%;
    min-height: 2.25rem;
    font-size: 0.82rem;
    font-weight: 500;
  }

  #totalBudget {
    font-size: 1rem;
    font-weight: 500;
    padding: 0.45rem 0.55rem;
    border-width: 1px;
    min-height: auto;
  }

  .currency {
    font-size: 0.95rem;
    font-weight: 500;
  }

  .budget-card .lbl {
    font-size: 0.64rem;
    margin-bottom: 0.3rem;
  }

  .stat-hero {
    padding: 0.55rem 0.65rem;
    margin-top: 0.35rem;
  }

  .stat-hero-lbl {
    font-size: 0.68rem;
  }

  .stat-hero-val {
    font-size: 1.05rem;
    font-weight: 650;
  }

  .stat-chip-val,
  .pay-left-val {
    font-size: 0.92rem;
    font-weight: 600;
  }

  .stat-chip-lbl,
  .pay-left-lbl,
  .stat-hero-lbl,
  .sidebar-block-title {
    font-size: 0.64rem;
  }

  .sidebar-title {
    font-size: 0.95rem;
  }

  .sidebar-hint,
  .block-hint {
    font-size: 0.74rem;
  }

  .actions .btn {
    min-height: 2.35rem;
    font-size: 0.84rem;
  }

  .btn.primary {
    min-height: 2.4rem;
    font-size: 0.86rem;
    font-weight: 500;
  }

  .person-breakdown {
    gap: 0.45rem;
  }

  .stat-chip,
  .pay-left-chip {
    padding: 0.5rem 0.6rem;
  }

  .sidebar-block {
    padding: 0.65rem;
  }

  .person-card {
    padding: 0.6rem;
  }

  .person-name {
    font-size: 0.88rem;
  }

  .person-metric-val {
    font-size: 0.92rem;
    font-weight: 600;
  }

  .summary .stat-val {
    font-size: 0.92rem;
    font-weight: 600;
  }

  .final-person-grid {
    grid-template-columns: 1fr;
    gap: 0.45rem;
  }

  .final-person-row {
    grid-template-columns: 1fr;
    gap: 0.2rem;
  }

  .final-person-vs {
    grid-column: 1;
    grid-row: auto;
  }
}

.line input[type="text"] {
  padding: 0.45rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
}

.line input.amount,
.line input.deposit {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.line select.paid-by {
  padding: 0.4rem 0.35rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.82rem;
  font-family: inherit;
  background: #fff;
  width: 100%;
}

.pay-method {
  display: flex;
  gap: 0.2rem;
  width: 100%;
}

.pay-btn {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fafaf9;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 600;
  font-family: inherit;
  padding: 0.38rem 0.15rem;
  cursor: pointer;
  line-height: 1.1;
}

.pay-btn.cash.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.pay-btn.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.pay-btn.credit.active {
  background: #eff6ff;
  border-color: #2563eb;
  color: #1d4ed8;
}

.pay-btn.debit.active {
  background: #f5f3ff;
  border-color: #7c3aed;
  color: #6d28d9;
}

.line-left {
  text-align: right;
  font-weight: 700;
  font-size: 0.88rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.line-left.warn {
  color: var(--warn);
}

.line-left.pos {
  color: var(--good);
}

.line-left.line-left-paid {
  font-size: 0.78rem;
  letter-spacing: 0.02em;
}

.line.line-paid {
  background: #ecfdf5;
  border-radius: 8px;
  padding: 0.15rem 0.2rem;
}

.line.line-paid .deposit {
  background: #f0fdf4;
  border-color: #bbf7d0;
}

.line-paid-btn {
  padding: 0.32rem 0.35rem;
  font-size: 0.68rem;
  min-width: 0;
  background: #fafaf9;
  color: var(--muted);
  border: 1px solid var(--border);
}

.line-paid-btn.active {
  background: #ecfdf5;
  border-color: #86efac;
  color: var(--good);
}

.line-left.neg {
  color: var(--bad);
}

.btn {
  border: none;
  border-radius: 10px;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  padding: 0.45rem 0.75rem;
  font-family: inherit;
}

.btn.secondary {
  background: var(--accent-soft);
  color: var(--accent);
}

.btn.secondary:hover {
  filter: brightness(0.97);
}

.btn.primary {
  background: var(--accent);
  color: #fff;
  width: 100%;
  padding: 0.65rem 1rem;
}

.btn.primary:hover {
  filter: brightness(1.05);
}

.btn.primary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn.ghost {
  background: transparent;
  color: var(--muted);
  width: 100%;
  margin-top: 0.35rem;
}

.btn.danger {
  background: transparent;
  color: var(--bad);
  padding: 0.35rem 0.5rem;
  font-size: 1rem;
  line-height: 1;
}

.summary .stat {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 0.35rem 0;
  border-bottom: 1px solid var(--border);
}

.summary .stat.highlight-stat {
  background: var(--accent-soft);
  margin: 0.25rem -0.5rem;
  padding: 0.5rem 0.5rem;
  border-radius: 8px;
  border-bottom: none;
}

.summary .stat.highlight-stat .stat-val {
  font-size: 1.15rem;
}

.summary .stat.highlight-stat .stat-val.warn {
  color: var(--warn);
}

.summary .stat.highlight-stat .stat-val.pos {
  color: var(--good);
}

.sidebar-stat.highlight .stat-val.warn {
  color: var(--warn);
}

.sidebar-stat.highlight .stat-val.pos {
  color: var(--good);
}

.stat-val.warn {
  color: var(--warn);
}

.stat-val.pos {
  color: var(--good);
}

.sidebar-stat.highlight .stat-val.warn {
  color: var(--warn);
}

.sidebar-stat.highlight .stat-val.pos {
  color: var(--good);
}

.summary .stat.wide {
  flex-wrap: wrap;
  gap: 0.35rem;
}

.stat-lbl {
  color: var(--muted);
  font-size: 0.88rem;
}

.stat-val {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-size: 1.05rem;
}

.bar-wrap {
  flex: 1 1 100%;
  height: 10px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.bar {
  height: 100%;
  width: 0%;
  background: var(--good);
  border-radius: 999px;
  transition: width 0.2s ease, background 0.2s;
}

.bar.over {
  background: var(--bad);
}

.pct {
  font-size: 0.82rem;
  color: var(--muted);
  width: 100%;
  text-align: right;
}

.status-msg {
  margin: 0.65rem 0 0;
  min-height: 1.35rem;
  font-size: 0.88rem;
}

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

.status-msg.warn {
  color: var(--warn);
}

.status-msg.bad {
  color: var(--bad);
}

.actions {
  margin-top: 0.75rem;
}

.remaining.neg {
  color: var(--bad);
}

.remaining.pos {
  color: var(--good);
}

.balance-due.pos {
  color: var(--good);
}

.balance-due.neg {
  color: var(--bad);
}

.print-only {
  display: none;
}

body.pdf-export {
  background: #fff;
}

body.pdf-export .no-print,
body.pdf-export .pdf-hide,
body.pdf-export .line-remove {
  display: none !important;
}

body.pdf-export .print-only {
  display: block;
}

body.pdf-export .summary-details-summary {
  display: none;
}

body.pdf-export .layout {
  display: block;
  max-width: none;
  padding: 0;
}

body.pdf-export .person-breakdown {
  flex-direction: row;
  gap: 0.5rem;
}

body.pdf-export .line.empty-line {
  display: none !important;
}

@media print {
  body {
    background: #fff;
    font-size: 10.5pt;
    line-height: 1.35;
  }

  .print-only {
    display: block;
  }

  .no-print,
  .pdf-hide,
  .line-remove {
    display: none !important;
  }

  .layout {
    display: block;
    max-width: none;
    padding: 0.45in;
  }

  .shell,
  .sidebar {
    width: 100%;
    margin: 0;
    padding: 0;
  }

  .sidebar {
    position: static;
    margin-top: 0.65rem;
    break-inside: avoid;
  }

  .card {
    box-shadow: none;
    border: 1px solid #ccc;
    border-radius: 8px;
    padding: 0.55rem 0.65rem;
    margin-top: 0.45rem;
    break-inside: avoid;
  }

  .head h1 {
    font-size: 1.15rem;
    margin-bottom: 0.15rem;
  }

  .print-date,
  #printDate {
    margin: 0 0 0.35rem;
    font-size: 0.8rem;
    color: #666;
  }

  .print-section-title {
    margin: 0 0 0.35rem;
    font-size: 0.95rem;
  }

  .line-headers,
  .line {
    grid-template-columns: 2.2fr 1fr 1fr 1fr 1fr;
    gap: 0.35rem;
  }

  .line.empty-line {
    display: none !important;
  }

  .line-headers {
    font-size: 0.68rem;
    border-bottom: 1px solid #bbb;
    margin-bottom: 0.2rem;
    padding-bottom: 0.2rem;
  }

  .line {
    padding: 0.15rem 0;
    border-bottom: 1px solid #eee;
  }

  .line:last-child {
    border-bottom: none;
  }

  .line input,
  .line select {
    border: none;
    background: transparent;
    padding: 0;
    font-size: 0.82rem;
    -webkit-appearance: none;
    appearance: none;
  }

  .line-left {
    font-size: 0.82rem;
  }

  .summary .stat {
    padding: 0.2rem 0;
  }

  .summary .stat.highlight-stat {
    margin: 0;
    padding: 0.25rem 0;
    background: transparent;
  }

  .summary .stat.highlight-stat .stat-val {
    font-size: 1rem;
  }

  .stat-lbl {
    font-size: 0.82rem;
  }

  .stat-val {
    font-size: 0.92rem;
  }

  .person-breakdown {
    flex-direction: row;
    gap: 0.5rem;
    margin-top: 0.35rem;
  }

  .person-card {
    flex: 1;
    padding: 0.45rem 0.55rem;
    border: 1px solid #ddd;
  }

  .person-name {
    font-size: 0.85rem;
    margin-bottom: 0.25rem;
  }

  .person-card .sidebar-stat {
    padding: 0.15rem 0;
  }

  .sidebar-title {
    font-size: 0.95rem;
    margin-bottom: 0.35rem;
  }

  @page {
    size: letter portrait;
    margin: 0;
  }
}
